Skip to content

Commit

Permalink
feat(language): add support for tool hub variables #100
Browse files Browse the repository at this point in the history
Add support for ToolHubVariable in DevInsCompiler and ToolHubVariable.kt. ToolHubVariable now provides a lookup function to retrieve a list of agents or commands based on the variable name.
  • Loading branch information
phodal committed Mar 21, 2024
1 parent 11cc6df commit 2796660
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Expand Up @@ -5,6 +5,7 @@ import cc.unitmesh.devti.custom.compile.VariableTemplateCompiler
import cc.unitmesh.devti.language.compiler.exec.*
import cc.unitmesh.devti.language.completion.dataprovider.BuiltinCommand
import cc.unitmesh.devti.language.completion.dataprovider.CustomCommand
import cc.unitmesh.devti.language.completion.dataprovider.ToolHubVariable
import cc.unitmesh.devti.language.parser.CodeBlockElement
import cc.unitmesh.devti.language.psi.DevInFile
import cc.unitmesh.devti.language.psi.DevInTypes
Expand Down Expand Up @@ -110,6 +111,13 @@ class DevInsCompiler(
}

DevInTypes.VARIABLE_START -> {
val variableId = id?.text
val variable = ToolHubVariable.lookup(myProject, variableId)
if (variable.isNotEmpty()) {
output.append(variable.first())
return
}

if (editor == null || element == null) {
output.append("<DevInsError> No context editor found for variable: ${used.text}")
result.hasError = true
Expand Down
@@ -1,6 +1,8 @@
package cc.unitmesh.devti.language.completion.dataprovider

import cc.unitmesh.devti.agent.model.CustomAgentConfig
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.NlsSafe

/**
* The tool hub provides a list of tools - agents and commands for the AI Agent to decide which one to call
Expand All @@ -11,8 +13,8 @@ import cc.unitmesh.devti.agent.model.CustomAgentConfig
* ```
*/
enum class ToolHubVariable(val summaryName: String, val type: String, val description: String) {
AGENT("agent", CustomAgentConfig::class.simpleName.toString(), "DevIns all agent for AI Agent to call"),
COMMAND("command", BuiltinCommand::class.simpleName.toString(), "DevIns all commands for AI Agent to call"),
AGENTS("agents", CustomAgentConfig::class.simpleName.toString(), "DevIns all agent for AI Agent to call"),
COMMANDS("commands", BuiltinCommand::class.simpleName.toString(), "DevIns all commands for AI Agent to call"),

;

Expand All @@ -21,6 +23,16 @@ enum class ToolHubVariable(val summaryName: String, val type: String, val descri
return values().toList()
}

// fun examples from resources

/**
* @param variableId should be one of the [ToolHubVariable] name
*/
fun lookup(myProject: Project, variableId: @NlsSafe String?): List<String> {
return when (variableId) {
AGENTS.name -> CustomAgentConfig.loadFromProject(myProject).map { it.name }
COMMANDS.name -> BuiltinCommand.all().map { it.commandName }
else -> emptyList()
}
}
}
}

0 comments on commit 2796660

Please sign in to comment.