Skip to content

Commit fe78ae3

Browse files
committed
refactor(agent): use centralized method to load custom rag apps #195
Use centralized method `CustomAgentConfig.loadFromProject` to load custom rag apps in `AutoDevInputSection` and `TestCodeGenTask`. Remove duplicate code and improve code readability.
1 parent 0dfaa32 commit fe78ae3

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

src/main/kotlin/cc/unitmesh/devti/agent/configurable/CoUnitSettingService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class CoUnitProjectSettingsService(
1212
val project: Project,
1313
) : SimplePersistentStateComponent<CoUnitProjectSettingsService.CoUnitProjectSettings>(CoUnitProjectSettings()) {
1414
val enableCustomRag: Boolean get() = state.enableCustomRag
15+
16+
/**
17+
* Use [cc.unitmesh.devti.agent.model.CustomAgentConfig.loadFromProject]
18+
*/
1519
val ragsJsonConfig: String get() = state.agentJsonConfig
1620

1721
fun modify(action: (CoUnitProjectSettings) -> Unit) {

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,9 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
183183
}
184184

185185
private fun loadRagApps(): List<CustomAgentConfig> {
186-
val ragsJsonConfig = project.customAgentSetting.ragsJsonConfig
187-
if (ragsJsonConfig.isEmpty()) return listOf(defaultRag)
188-
189-
val rags = try {
190-
Json.decodeFromString<List<CustomAgentConfig>>(ragsJsonConfig)
191-
} catch (e: Exception) {
192-
logger.warn("Failed to parse custom rag apps", e)
193-
listOf()
194-
}
186+
val rags = CustomAgentConfig.loadFromProject(project)
187+
188+
if (rags.isEmpty()) return listOf(defaultRag)
195189

196190
return listOf(defaultRag) + rags
197191
}

src/main/kotlin/cc/unitmesh/devti/intentions/action/task/TestCodeGenTask.kt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,8 @@ class TestCodeGenTask(val request: TestCodeGenRequest) :
210210
}
211211

212212
private fun loadRagApp(): CustomAgentConfig? {
213-
val ragsJsonConfig = project.customAgentSetting.ragsJsonConfig
214-
if (ragsJsonConfig.isEmpty()) return null
215-
216-
val rags = try {
217-
Json.decodeFromString<List<CustomAgentConfig>>(ragsJsonConfig)
218-
} catch (e: Exception) {
219-
logger.warn("Failed to parse custom rag apps", e)
220-
listOf()
221-
}
222-
223-
if (rags.isEmpty()) {
224-
return null
225-
}
226-
213+
val rags = CustomAgentConfig.loadFromProject(project)
214+
if (rags.isEmpty()) return null
227215

228216
return rags.firstOrNull { it.name == CustomExtContext.TextContext.agentName }
229217
}

0 commit comments

Comments
 (0)