Skip to content

Commit 27d1269

Browse files
committed
feat(gui): add support for custom rag apps selection #51
Enable users to select from a list of custom rag apps to configure the development environment. This feature enhances the flexibility and customization options for developers, allowing them to tailor their workflows to their specific needs. The selection is dynamically loaded from a configurable JSON file, ensuring ease of maintenance and extensibility.
1 parent 3f19fae commit 27d1269

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/main/kotlin/cc/unitmesh/devti/counit/model/CustomRagApp.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package cc.unitmesh.devti.counit.model
22

3+
import cc.unitmesh.devti.custom.team.InteractionType
4+
import kotlinx.serialization.Serializable
5+
36
/**
47
* Enumeration of possible response actions.
58
*
@@ -24,6 +27,7 @@ enum class ResponseAction {
2427
Flow
2528
}
2629

30+
@Serializable
2731
data class CustomFlowTransition(
2832
/**
2933
* will be JsonPath
@@ -35,11 +39,13 @@ data class CustomFlowTransition(
3539
val target: String,
3640
)
3741

42+
@Serializable
3843
data class CustomRagApp(
3944
val name: String,
4045
val description: String = "",
4146
val url: String = "",
4247
val icon: String = "",
4348
val responseAction: ResponseAction = ResponseAction.Direct,
4449
val customFlowTransition: List<CustomFlowTransition> = emptyList(),
50+
val interactive: InteractionType = InteractionType.ChatPanel,
4551
)

src/main/kotlin/cc/unitmesh/devti/gui/chat/AutoDevInputSection.kt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package cc.unitmesh.devti.gui.chat
22

33
import cc.unitmesh.devti.AutoDevBundle
44
import cc.unitmesh.devti.AutoDevIcons
5+
import cc.unitmesh.devti.counit.configurable.customRagSettings
6+
import cc.unitmesh.devti.counit.model.CustomRagApp
57
import cc.unitmesh.devti.llms.tokenizer.Tokenizer
68
import cc.unitmesh.devti.llms.tokenizer.TokenizerImpl
79
import cc.unitmesh.devti.settings.AutoDevSettingsState
810
import com.intellij.openapi.Disposable
911
import com.intellij.openapi.actionSystem.AnActionEvent
1012
import com.intellij.openapi.actionSystem.Presentation
1113
import com.intellij.openapi.actionSystem.impl.ActionButton
14+
import com.intellij.openapi.diagnostic.logger
1215
import com.intellij.openapi.editor.event.DocumentEvent
1316
import com.intellij.openapi.editor.event.DocumentListener
1417
import com.intellij.openapi.editor.ex.EditorEx
@@ -20,13 +23,19 @@ import com.intellij.openapi.ui.ValidationInfo
2023
import com.intellij.openapi.wm.IdeFocusManager
2124
import com.intellij.openapi.wm.impl.InternalDecorator
2225
import com.intellij.temporary.gui.block.AutoDevCoolBorder
26+
import com.intellij.ui.CollectionComboBoxModel
2327
import com.intellij.ui.JBColor
28+
import com.intellij.ui.MutableCollectionComboBoxModel
29+
import com.intellij.ui.SimpleListCellRenderer
30+
import com.intellij.ui.components.JBLabel
2431
import com.intellij.ui.content.ContentManager
2532
import com.intellij.util.EventDispatcher
2633
import com.intellij.util.ui.JBEmptyBorder
2734
import com.intellij.util.ui.JBUI
2835
import com.intellij.util.ui.UIUtil
2936
import com.intellij.util.ui.components.BorderLayoutPanel
37+
import kotlinx.serialization.json.Json
38+
import kotlinx.serialization.decodeFromString
3039
import java.awt.Color
3140
import java.awt.Component
3241
import java.awt.Dimension
@@ -46,7 +55,8 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
4655
private val documentListener: DocumentListener
4756
private val buttonPresentation: Presentation
4857
private val button: ActionButton
49-
private val customRag: ComboBox<String>
58+
private val customRag: ComboBox<CustomRagApp>
59+
private val logger = logger<AutoDevInputSection>()
5060

5161
val editorListeners: EventDispatcher<AutoDevInputListener> =
5262
EventDispatcher.create(AutoDevInputListener::class.java)
@@ -93,7 +103,6 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
93103
input.border = JBEmptyBorder(4)
94104

95105
addToCenter(input)
96-
97106
val layoutPanel = BorderLayoutPanel()
98107
val horizontalGlue = Box.createHorizontalGlue()
99108
horizontalGlue.addMouseListener(object : MouseAdapter() {
@@ -107,9 +116,12 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
107116
JBColor(3684930, 3750720)
108117
)
109118
layoutPanel.setOpaque(false)
110-
customRag = ComboBox(arrayOf("Normal")).also {
111-
// todo: load from json config
112-
}
119+
customRag = ComboBox(MutableCollectionComboBoxModel(loadRagApps()))
120+
customRag.setRenderer(SimpleListCellRenderer.create { label: JBLabel, value: CustomRagApp?, _: Int ->
121+
if (value != null) {
122+
label.text = value.name
123+
}
124+
})
113125

114126
layoutPanel.addToLeft(customRag)
115127
layoutPanel.addToCenter(horizontalGlue)
@@ -131,6 +143,19 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
131143
tokenizer = TokenizerImpl.INSTANCE
132144
}
133145

146+
private fun loadRagApps(): List<CustomRagApp> {
147+
val ragsJsonConfig = project.customRagSettings.ragsJsonConfig
148+
val rags = try {
149+
Json.decodeFromString<List<CustomRagApp>>(ragsJsonConfig)
150+
} catch (e: Exception) {
151+
logger.warn("Failed to parse custom rag apps", e)
152+
listOf()
153+
}
154+
155+
val firstRag = CustomRagApp("Normal", "Normal")
156+
return listOf(firstRag) + rags
157+
}
158+
134159
fun initEditor() {
135160
val editorEx = when (this.input.editor) {
136161
is EditorEx -> this.input.editor

0 commit comments

Comments
 (0)