Skip to content

Commit 100f1c4

Browse files
committed
refactor(agenttool): simplify AgentTool structure and remove unused files #308
- Removed unused files: BrowseTool.kt, AgentToolContext.kt, AgentToolResult.kt, and BrowseToolTest.kt. - Simplified AgentTool interface to a data class with commandName, description, and example. - Updated SketchToolchainProvider to use the new AgentTool data class. - Modified BridgeRunContext to use BridgeToolProvider for tool list collection. - Added new Browse.kt class for parsing HTML. - Updated XML and Kotlin files to reflect the new structure and dependencies.
1 parent 49b3ee1 commit 100f1c4

File tree

11 files changed

+36
-103
lines changed

11 files changed

+36
-103
lines changed
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
package cc.unitmesh.devti.agenttool
22

3-
import com.intellij.openapi.extensions.ExtensionPointName
4-
5-
interface AgentTool {
6-
val name: String
7-
val description: String
8-
fun execute(context: AgentToolContext): AgentToolResult
9-
10-
// extension point
11-
companion object {
12-
val EP_NAME = ExtensionPointName<AgentTool>("devins.agentTool")
13-
14-
fun allTools(): List<AgentTool> {
15-
return EP_NAME.extensionList
16-
}
17-
}
18-
}
3+
data class AgentTool(val commandName: String, val description: String, val example: String) {
4+
override fun toString(): String =
5+
"""<tool>name: ${commandName}, desc: $description, example:
6+
<devin>
7+
$example
8+
</devin>
9+
</tool>"""
10+
}

core/src/main/kotlin/cc/unitmesh/devti/agenttool/AgentToolContext.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.

core/src/main/kotlin/cc/unitmesh/devti/agenttool/AgentToolResult.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cc.unitmesh.devti.agenttool.browse
2+
3+
import org.jsoup.Jsoup
4+
import org.jsoup.nodes.Document
5+
6+
class Browse {
7+
companion object {
8+
/**
9+
* Doc for parseHtml
10+
*
11+
* Intellij API: [com.intellij.inspectopedia.extractor.utils.HtmlUtils.cleanupHtml]
12+
*/
13+
fun parse(url: String): DocumentContent {
14+
val doc: Document = Jsoup.connect(url).get()
15+
return DocumentCleaner().cleanHtml(doc)
16+
}
17+
}
18+
}
19+

core/src/main/kotlin/cc/unitmesh/devti/agenttool/browse/BrowseTool.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

core/src/main/kotlin/cc/unitmesh/devti/bridge/BridgeRunContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ data class BridgeRunContext(
7373
relatedFiles = emptyList(),
7474
userInput = input,
7575
workspace = workspace(project),
76-
toolList = SketchToolchainProvider.collect(project).joinToString("\n"),
76+
toolList = BridgeToolProvider.collect(project),
7777
shell = ShellUtil.detectShells().firstOrNull() ?: "/bin/bash",
7878
frameworkContext = runBlocking {
7979
return@runBlocking ChatContextProvider.collectChatContextList(project, creationContext)

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchToolchainProvider.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
package cc.unitmesh.devti.sketch
22

3+
import cc.unitmesh.devti.agenttool.AgentTool
34
import com.intellij.openapi.extensions.ExtensionPointName
45
import com.intellij.openapi.project.Project
56

6-
data class Toolchain(val commandName: String, val description: String, val example: String) {
7-
override fun toString(): String =
8-
"""<tool>name: ${commandName}, desc: $description, example:
9-
<devin>
10-
$example
11-
</devin>
12-
</tool>"""
13-
}
14-
157
interface SketchToolchainProvider {
16-
fun collect(): List<Toolchain>
8+
fun collect(): List<AgentTool>
179

1810
companion object {
1911
private val EP_NAME: ExtensionPointName<SketchToolchainProvider> =
2012
ExtensionPointName.create("cc.unitmesh.sketchToolchainProvider")
2113

22-
fun collect(project: Project): List<Toolchain> {
14+
fun collect(project: Project): List<AgentTool> {
2315
return EP_NAME.extensionList.flatMap {
2416
it.collect()
2517
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsSketchToolchainProvider.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ package cc.unitmesh.devti.language.compiler
22

33
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
44
import cc.unitmesh.devti.sketch.SketchToolchainProvider
5-
import cc.unitmesh.devti.sketch.Toolchain
5+
import cc.unitmesh.devti.agenttool.AgentTool
66

77
class DevInsSketchToolchainProvider : SketchToolchainProvider {
8-
override fun collect(): List<Toolchain> {
8+
override fun collect(): List<AgentTool> {
99
/// we need to ignore some bad case for llm
1010
return BuiltinCommand.all()
1111
.filter {
1212
it.enableInSketch
1313
}
1414
.map {
1515
val example = BuiltinCommand.example(it)
16-
Toolchain(it.commandName, it.description, example)
16+
AgentTool(it.commandName, it.description, example)
1717
}
1818
}
1919
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/BrowseInsCommand.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.unitmesh.devti.language.compiler.exec
22

3-
import cc.unitmesh.devti.agenttool.browse.BrowseTool
3+
import cc.unitmesh.devti.agenttool.browse.Browse
44
import cc.unitmesh.devti.devin.InsCommand
55
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
66
import com.intellij.openapi.project.Project
@@ -9,7 +9,7 @@ class BrowseInsCommand(val myProject: Project, private val prop: String) : InsCo
99
override val commandName: BuiltinCommand = BuiltinCommand.BROWSE
1010

1111
override suspend fun execute(): String? {
12-
val parse = BrowseTool.parse(prop)
12+
val parse = Browse.parse(prop)
1313
return parse.body
1414
}
1515
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@
5555
implementationClass="cc.unitmesh.devti.language.lints.DevInsDuplicateAgentInspection"/>
5656
</extensions>
5757

58-
<extensionPoints>
59-
<extensionPoint qualifiedName="devins.agentTool"
60-
interface="cc.unitmesh.devti.agenttool.AgentTool"
61-
dynamic="true"/>
62-
</extensionPoints>
6358

6459
<actions>
6560
<action id="runDevInsFileAction"

exts/devins-lang/src/test/kotlin/cc/unitmesh/devti/language/agenttool/scrapy/BrowseToolTest.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)