Skip to content

Commit 4cc3dd8

Browse files
committed
feat(tools): enhance AgentTool and add new tool examples #308
- Refactor `AgentTool` toString method for better formatting. - Implement `toolInfo` in `DatabaseFunctionProvider` to return `AgentTool` instance. - Add new tool examples for component view, styling view, container view, history, dependencies, and SCC. - Update `BridgeToolProvider` to include function tools from `ToolchainFunctionProvider`. - Add test case for loading all bridge command examples.
1 parent e9c3fbc commit 4cc3dd8

File tree

13 files changed

+73
-17
lines changed

13 files changed

+73
-17
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package cc.unitmesh.devti.agenttool
22

33
data class AgentTool(val commandName: String, val description: String, val example: String) {
4-
override fun toString(): String =
5-
"""<tool>name: ${commandName}, desc: $description, example:
4+
override fun toString(): String {
5+
// val string = """desc: $description"""
6+
val string = if (description.isEmpty()) "" else """desc: $description"""
7+
return """<tool>name: ${commandName}, $string
8+
example:
69
<devin>
710
$example
811
</devin>
912
</tool>"""
13+
}
1014
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.devti.bridge
33
import cc.unitmesh.devti.agenttool.AgentTool
44
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
55
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand.*
6+
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
67
import com.intellij.openapi.project.Project
78

89
object BridgeToolProvider {
@@ -14,9 +15,21 @@ object BridgeToolProvider {
1415
.map {
1516
val example = BuiltinCommand.example(it)
1617
AgentTool(it.commandName, it.description, example)
18+
}.toMutableList()
19+
20+
val functions = ToolchainFunctionProvider.all()
21+
22+
commonTools += functions.map {
23+
if (it.toolInfo() != null) {
24+
return@map listOf(it.toolInfo()!!)
1725
}
1826

19-
/// collect function tools in Bridge.kt
27+
val funcNames = it.funcNames()
28+
funcNames.map { name ->
29+
val example = BuiltinCommand.example(name)
30+
AgentTool(name, "", example)
31+
}
32+
}.flatten()
2033

2134
return commonTools
2235
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import com.intellij.openapi.project.Project
99

1010
class BridgeToolWindow(val myProject: Project, val myEditor: Editor?, private val showInput: Boolean = false) :
1111
SketchToolWindow(myProject, myEditor, showInput, ChatActionType.BRIDGE) {
12-
override val inputListener = object : SketchInputListener(project, chatCodingService, this) {
12+
override val inputListener
13+
get() = object : SketchInputListener(project, chatCodingService, this) {
14+
init {
15+
// no super
16+
val template = templateRender.getTemplate("bridge.vm")
17+
var systemPrompt = ""
18+
val customContext = BridgeRunContext.create(project, null, "")
1319

14-
init {
15-
// no super
16-
val template = templateRender.getTemplate("bridge.vm")
17-
var systemPrompt = ""
18-
val customContext = BridgeRunContext.create(project, null, "")
19-
20-
systemPrompt = templateRender.renderTemplate(template, customContext)
21-
invokeLater {
22-
toolWindow.addSystemPrompt(systemPrompt)
20+
systemPrompt = templateRender.renderTemplate(template, customContext)
21+
invokeLater {
22+
toolWindow.addSystemPrompt(systemPrompt)
23+
}
2324
}
2425
}
25-
}
2626
}

core/src/main/kotlin/cc/unitmesh/devti/provider/toolchain/ToolchainFunctionProvider.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package cc.unitmesh.devti.provider.toolchain
22

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

67
interface ToolchainFunctionProvider {
8+
fun toolInfo(): AgentTool? = null
9+
710
fun funcNames(): List<String>
811

912
fun isApplicable(project: Project, funcName: String): Boolean

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ open class SketchToolWindow(
6161
) :
6262
SimpleToolWindowPanel(true, true), NullableComponent, Disposable {
6363
open val chatCodingService = ChatCodingService(chatActionType, project)
64-
open val inputListener = SketchInputListener(project, chatCodingService, this)
64+
open val inputListener get() = SketchInputListener(project, chatCodingService, this)
6565
private var progressBar: CustomProgressBar = CustomProgressBar(this)
6666
private var inputSection: AutoDevInputSection = AutoDevInputSection(project, this, showAgent = false)
6767

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
List all UI Component List of current project, like React Vue components
2+
/componentView
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
List all modules of current project
2+
/moduleView
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Get all dependencies (Gradle, Maven, package.json) of current project
2+
/dependencies
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Get history commit message of current file
2+
/history:package.json
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Scc is a very fast accurate code counter with complexity calculations and COCOMO estimates
2+
/scc
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
List all CSS, SCSS classes of current project
2+
/stylingView
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cc.unitmesh.devti.language.completion.dataprovider
2+
3+
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
4+
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
5+
import com.intellij.testFramework.LightPlatformTestCase
6+
7+
class FunctionToolsCommandTest : LightPlatformTestCase() {
8+
fun testShouldLoadAllBridgeCommandExamples() {
9+
val functions = ToolchainFunctionProvider.all()
10+
11+
val map = functions.map {
12+
it.funcNames().map { name ->
13+
BuiltinCommand.example(name)
14+
}
15+
}
16+
17+
println(map)
18+
}
19+
}

exts/ext-database/src/main/kotlin/cc/unitmesh/database/provider/DatabaseFunctionProvider.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package cc.unitmesh.database.provider
22

33
import cc.unitmesh.database.util.DatabaseSchemaAssistant
44
import cc.unitmesh.database.util.DatabaseSchemaAssistant.getTableColumn
5+
import cc.unitmesh.devti.agenttool.AgentTool
56
import cc.unitmesh.devti.bridge.provider.DatabaseFunction
7+
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
68
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
79
import com.intellij.database.model.DasTable
810
import com.intellij.database.model.RawDataSource
@@ -12,10 +14,13 @@ import com.intellij.openapi.diagnostic.logger
1214
import com.intellij.openapi.project.Project
1315

1416
class DatabaseFunctionProvider : ToolchainFunctionProvider {
15-
override fun isApplicable(project: Project, funcName: String): Boolean {
16-
return DatabaseFunction.values().any { it.funName == funcName }
17+
override fun toolInfo(): AgentTool? {
18+
val example = BuiltinCommand.example("database")
19+
return AgentTool("database", "Database schema and query tool", example)
1720
}
1821

22+
override fun isApplicable(project: Project, funcName: String): Boolean = DatabaseFunction.entries.any { it.funName == funcName }
23+
1924
override fun funcNames(): List<String> = DatabaseFunction.allFuncNames()
2025

2126
override fun execute(

0 commit comments

Comments
 (0)