Skip to content

Commit 1efc73c

Browse files
committed
feat(provider): enable DevIn agent responses #101
This commit enables the execution of DevIn agent responses within the custom agent chat processor by adding a new interface for DevIn response providers and implementing a custom agent response provider for DevIn language. The DevIn custom agent response provider executes the DevIn code and notifies the project of the result.
1 parent e599196 commit 1efc73c

File tree

5 files changed

+90
-8
lines changed

5 files changed

+90
-8
lines changed

example/custom_agent/server.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,39 @@ def mock_devins(messages: Messages):
9393
Here are the patches for your
9494
9595
```devin
96-
/write:src/main/java/com/example/Controller.java#L1-L12
97-
\\`\\`\\`java
98-
public class Controller {
99-
public void method() {
100-
System.out.println("Hello, World!");
101-
}
102-
}
96+
/patch
97+
98+
\\`\\`\\`patch
99+
Index: src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java
100+
IDEA additional info:
101+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
102+
<+>UTF-8
103+
===================================================================
104+
diff --git a/src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java b/src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java
105+
--- a/src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java (revision b5985862c79fe42043697bc5d5f38b470020be3d)
106+
+++ b/src/main/java/cc/unitmesh/untitled/demo/controller/BlogCategoryController.java (date 1709616724534)
107+
@@ -4,7 +4,19 @@
108+
109+
@RestController
110+
public class BlogCategoryController {
111+
- // devti://story/github/1
112+
+ public void addCategory(String categoryName) {
113+
+ // ... add category logic here
114+
+ }
115+
+
116+
+ public void deleteCategory(long categoryId) {
117+
+ // ... delete category logic here
118+
+ }
119+
120+
- // Close a bank account
121+
+ public void updateCategory(long categoryId, String newCategoryName) {
122+
+ // ... update category logic here
123+
+ }
124+
+
125+
+ public void listCategories() {
126+
+ // ... list all categories logic here
127+
+ }
128+
}
103129
\\`\\`\\`
104130
```"""
105131

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cc.unitmesh.devti.language.provider
2+
3+
import cc.unitmesh.devti.AutoDevNotifications
4+
import cc.unitmesh.devti.language.DevInLanguage
5+
import cc.unitmesh.devti.language.compiler.DevInsCompiler
6+
import cc.unitmesh.devti.language.psi.DevInFile
7+
import cc.unitmesh.devti.provider.custom.AgentResponseProvider
8+
import cc.unitmesh.devti.provider.custom.CustomAgentContext
9+
import com.intellij.openapi.project.Project
10+
import com.intellij.psi.PsiFileFactory
11+
import java.util.*
12+
13+
14+
class DevInsCustomAgentResponse : AgentResponseProvider {
15+
override val name: String = "DevIn"
16+
17+
override fun execute(project: Project, context: CustomAgentContext): String {
18+
val filename = "DevIns-${UUID.randomUUID()}.devin"
19+
20+
val devInFile = PsiFileFactory.getInstance(project)
21+
.createFileFromText(filename, DevInLanguage, context.response) as DevInFile
22+
23+
val devInsCompiler = DevInsCompiler(project, devInFile)
24+
val result = devInsCompiler.compile()
25+
26+
AutoDevNotifications.notify(project, result.output)
27+
28+
return result.output
29+
}
30+
}

exts/devins-lang/src/main/resources/cc.unitmesh.devti.language.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@
4444
class="cc.unitmesh.devti.language.actions.DevInsRunFileAction"
4545
use-shortcut-of="RunClass"/>
4646
</actions>
47+
48+
<extensions defaultExtensionNs="cc.unitmesh">
49+
<customAgentResponse implementation="cc.unitmesh.devti.language.provider.DevInsCustomAgentResponse" />
50+
</extensions>
4751
</idea-plugin>

src/main/kotlin/cc/unitmesh/devti/agent/CustomAgentChatProcessor.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import cc.unitmesh.devti.gui.chat.ChatCodingPanel
88
import cc.unitmesh.devti.gui.chat.ChatRole
99
import cc.unitmesh.devti.llms.LLMProvider
1010
import cc.unitmesh.devti.provider.ContextPrompter
11+
import cc.unitmesh.devti.provider.custom.AgentResponseProvider
12+
import cc.unitmesh.devti.provider.custom.CustomAgentContext
1113
import cc.unitmesh.devti.util.LLMCoroutineScope
14+
import cc.unitmesh.devti.util.parser.Code
1215
import com.intellij.openapi.components.Service
1316
import com.intellij.openapi.components.service
1417
import com.intellij.openapi.diagnostic.logger
@@ -38,6 +41,8 @@ class CustomAgentChatProcessor(val project: Project) {
3841
}
3942

4043
selectedAgent.state = CustomAgentState.FINISHED
44+
45+
var devInCode: String? = ""
4146
when (selectedAgent.responseAction) {
4247
CustomAgentResponseAction.Direct -> {
4348
val message = ui.addMessage("loading", false, "")
@@ -50,6 +55,12 @@ class CustomAgentChatProcessor(val project: Project) {
5055
val content = sb.toString().removeSurrounding("\"")
5156
llmProvider.appendLocalMessage(content, ChatRole.Assistant)
5257
message.reRenderAssistantOutput()
58+
59+
val code = Code.parse(content)
60+
if (code.language.displayName == "DevIn") {
61+
devInCode = code.text
62+
}
63+
5364
ui.hiddenProgressBar()
5465
ui.updateUI()
5566
}
@@ -64,6 +75,11 @@ class CustomAgentChatProcessor(val project: Project) {
6475
llmProvider.appendLocalMessage(msg, ChatRole.Assistant)
6576
ui.hiddenProgressBar()
6677
ui.updateUI()
78+
79+
val code = Code.parse(msg)
80+
if (code.language.displayName == "DevIn") {
81+
devInCode = code.text
82+
}
6783
}
6884

6985
CustomAgentResponseAction.TextChunk -> {
@@ -101,5 +117,11 @@ class CustomAgentChatProcessor(val project: Project) {
101117
ui.hiddenProgressBar()
102118
}
103119
}
120+
121+
if (!devInCode.isNullOrEmpty()) {
122+
AgentResponseProvider.instance("DevIn").forEach {
123+
it.execute(project, CustomAgentContext(selectedAgent, devInCode))
124+
}
125+
}
104126
}
105127
}

src/main/kotlin/cc/unitmesh/devti/provider/custom/AgentResponseProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ data class CustomAgentContext(
1010
val response: String
1111
)
1212

13-
internal interface AgentResponseProvider {
13+
interface AgentResponseProvider {
1414
val name: String
1515

1616
@RequiresBackgroundThread

0 commit comments

Comments
 (0)