diff --git a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt index 79756ca920..ba4d1f8ba5 100644 --- a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt +++ b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt @@ -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 @@ -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(" No context editor found for variable: ${used.text}") result.hasError = true diff --git a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/ToolHubVariable.kt b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/ToolHubVariable.kt index a306158878..026b8026cc 100644 --- a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/ToolHubVariable.kt +++ b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/ToolHubVariable.kt @@ -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 @@ -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"), ; @@ -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 { + return when (variableId) { + AGENTS.name -> CustomAgentConfig.loadFromProject(myProject).map { it.name } + COMMANDS.name -> BuiltinCommand.all().map { it.commandName } + else -> emptyList() + } + } } } \ No newline at end of file