mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-02-22 23:13:21 -05:00
feat: Add tools permissions (#238)
This commit is contained in:
@ -29,6 +29,14 @@ namespace QodeAssist::LLMCore {
|
||||
|
||||
enum class ToolSchemaFormat { OpenAI, Claude, Ollama, Google };
|
||||
|
||||
enum ToolPermission {
|
||||
None = 0,
|
||||
FileSystemRead = 1 << 0,
|
||||
FileSystemWrite = 1 << 1,
|
||||
NetworkAccess = 1 << 2
|
||||
};
|
||||
Q_DECLARE_FLAGS(ToolPermissions, ToolPermission)
|
||||
|
||||
class BaseTool : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -40,6 +48,7 @@ public:
|
||||
virtual QString stringName() const = 0;
|
||||
virtual QString description() const = 0;
|
||||
virtual QJsonObject getDefinition(ToolSchemaFormat format) const = 0;
|
||||
virtual ToolPermissions requiredPermissions() const = 0;
|
||||
|
||||
virtual QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) = 0;
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
#include "settings/ProviderSettings.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
@ -99,7 +100,7 @@ void ClaudeProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (supportsTools() && type == LLMCore::RequestType::Chat
|
||||
&& Settings::chatAssistantSettings().useTools()) {
|
||||
&& Settings::generalSettings().useTools()) {
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::Claude);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
#include "settings/ProviderSettings.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
@ -102,7 +103,7 @@ void GoogleAIProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (supportsTools() && type == LLMCore::RequestType::Chat
|
||||
&& Settings::chatAssistantSettings().useTools()) {
|
||||
&& Settings::generalSettings().useTools()) {
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::Google);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
#include "settings/ProviderSettings.hpp"
|
||||
|
||||
#include <QEventLoop>
|
||||
@ -250,7 +251,7 @@ void LMStudioProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (supportsTools() && type == LLMCore::RequestType::Chat
|
||||
&& Settings::chatAssistantSettings().useTools()) {
|
||||
&& Settings::generalSettings().useTools()) {
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QJsonArray>
|
||||
@ -101,7 +102,7 @@ void LlamaCppProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (supportsTools() && type == LLMCore::RequestType::Chat
|
||||
&& Settings::chatAssistantSettings().useTools()) {
|
||||
&& Settings::generalSettings().useTools()) {
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
#include "settings/ProviderSettings.hpp"
|
||||
|
||||
#include <QEventLoop>
|
||||
@ -271,7 +272,7 @@ void MistralAIProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (supportsTools() && type == LLMCore::RequestType::Chat
|
||||
&& Settings::chatAssistantSettings().useTools()) {
|
||||
&& Settings::generalSettings().useTools()) {
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
#include "settings/ProviderSettings.hpp"
|
||||
|
||||
namespace QodeAssist::Providers {
|
||||
@ -107,7 +108,7 @@ void OllamaProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (supportsTools() && type == LLMCore::RequestType::Chat
|
||||
&& Settings::chatAssistantSettings().useTools()) {
|
||||
&& Settings::generalSettings().useTools()) {
|
||||
auto toolsDefinitions = m_toolsManager->toolsFactory()->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::Ollama);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
#include "settings/ProviderSettings.hpp"
|
||||
|
||||
#include <QJsonArray>
|
||||
@ -101,7 +102,7 @@ void OpenAICompatProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (supportsTools() && type == LLMCore::RequestType::Chat
|
||||
&& Settings::chatAssistantSettings().useTools()) {
|
||||
&& Settings::generalSettings().useTools()) {
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "logger/Logger.hpp"
|
||||
#include "settings/ChatAssistantSettings.hpp"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
#include "settings/ProviderSettings.hpp"
|
||||
|
||||
#include <QEventLoop>
|
||||
@ -102,7 +103,7 @@ void OpenAIProvider::prepareRequest(
|
||||
}
|
||||
|
||||
if (supportsTools() && type == LLMCore::RequestType::Chat
|
||||
&& Settings::chatAssistantSettings().useTools()) {
|
||||
&& Settings::generalSettings().useTools()) {
|
||||
auto toolsDefinitions = m_toolsManager->getToolsDefinitions(
|
||||
LLMCore::ToolSchemaFormat::OpenAI);
|
||||
if (!toolsDefinitions.isEmpty()) {
|
||||
|
||||
@ -68,14 +68,6 @@ ChatAssistantSettings::ChatAssistantSettings()
|
||||
enableChatInNavigationPanel.setLabelText(Tr::tr("Enable chat in navigation panel"));
|
||||
enableChatInNavigationPanel.setDefaultValue(false);
|
||||
|
||||
useTools.setSettingsKey(Constants::CA_USE_TOOLS);
|
||||
useTools.setLabelText(Tr::tr("Enable tools"));
|
||||
useTools.setToolTip(
|
||||
Tr::tr(
|
||||
"Enable tool use capabilities for the assistant(OpenAI function calling, Claude tools "
|
||||
"and etc) "
|
||||
"if plugin and provider support"));
|
||||
useTools.setDefaultValue(true);
|
||||
|
||||
// General Parameters Settings
|
||||
temperature.setSettingsKey(Constants::CA_TEMPERATURE);
|
||||
@ -261,8 +253,7 @@ ChatAssistantSettings::ChatAssistantSettings()
|
||||
linkOpenFiles,
|
||||
autosave,
|
||||
enableChatInBottomToolBar,
|
||||
enableChatInNavigationPanel,
|
||||
useTools}},
|
||||
enableChatInNavigationPanel}},
|
||||
Space{8},
|
||||
Group{
|
||||
title(Tr::tr("General Parameters")),
|
||||
@ -324,7 +315,6 @@ void ChatAssistantSettings::resetSettingsToDefaults()
|
||||
resetAspect(codeFontSize);
|
||||
resetAspect(textFormat);
|
||||
resetAspect(chatRenderer);
|
||||
resetAspect(useTools);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -38,7 +38,6 @@ public:
|
||||
Utils::BoolAspect autosave{this};
|
||||
Utils::BoolAspect enableChatInBottomToolBar{this};
|
||||
Utils::BoolAspect enableChatInNavigationPanel{this};
|
||||
Utils::BoolAspect useTools{this};
|
||||
|
||||
// General Parameters Settings
|
||||
Utils::DoubleAspect temperature{this};
|
||||
|
||||
@ -205,6 +205,21 @@ GeneralSettings::GeneralSettings()
|
||||
caTemplateDescription.setDefaultValue("");
|
||||
caTemplateDescription.setLabelText(TrConstants::CURRENT_TEMPLATE_DESCRIPTION);
|
||||
|
||||
useTools.setSettingsKey(Constants::CA_USE_TOOLS);
|
||||
useTools.setLabelText(Tr::tr("Enable tools"));
|
||||
useTools.setToolTip(
|
||||
Tr::tr(
|
||||
"Enable tool use capabilities for the assistant(OpenAI function calling, Claude tools "
|
||||
"and etc) "
|
||||
"if plugin and provider support"));
|
||||
useTools.setDefaultValue(true);
|
||||
|
||||
allowFileSystemRead.setSettingsKey(Constants::CA_ALLOW_FILE_SYSTEM_READ);
|
||||
allowFileSystemRead.setLabelText(Tr::tr("Allow File System Read Access for tools"));
|
||||
allowFileSystemRead.setToolTip(
|
||||
Tr::tr("Allow tools to read files from disk (project files, open editors)"));
|
||||
allowFileSystemRead.setDefaultValue(true);
|
||||
|
||||
readSettings();
|
||||
|
||||
Logger::instance().setLoggingEnabled(enableLogging());
|
||||
@ -247,8 +262,10 @@ GeneralSettings::GeneralSettings()
|
||||
ccTemplateDescription,
|
||||
Row{specifyPreset1, preset1Language, Stretch{1}},
|
||||
ccPreset1Grid}};
|
||||
auto caGroup
|
||||
= Group{title(TrConstants::CHAT_ASSISTANT), Column{caGrid, caTemplateDescription}};
|
||||
|
||||
auto caGroup = Group{
|
||||
title(TrConstants::CHAT_ASSISTANT),
|
||||
Column{caGrid, Column{useTools, allowFileSystemRead}, caTemplateDescription}};
|
||||
|
||||
auto rootLayout = Column{
|
||||
Row{enableQodeAssist, Stretch{1}, Row{checkUpdate, resetToDefaults}},
|
||||
@ -492,6 +509,8 @@ void GeneralSettings::resetPageToDefaults()
|
||||
resetAspect(ccPreset1CustomEndpoint);
|
||||
resetAspect(caEndpointMode);
|
||||
resetAspect(caCustomEndpoint);
|
||||
resetAspect(useTools);
|
||||
resetAspect(allowFileSystemRead);
|
||||
writeSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,6 +100,9 @@ public:
|
||||
Utils::StringAspect caStatus{this};
|
||||
ButtonAspect caTest{this};
|
||||
|
||||
Utils::BoolAspect useTools{this};
|
||||
Utils::BoolAspect allowFileSystemRead{this};
|
||||
|
||||
Utils::StringAspect caTemplateDescription{this};
|
||||
|
||||
void showSelectionDialog(
|
||||
|
||||
@ -85,6 +85,7 @@ const char CC_CUSTOM_LANGUAGES[] = "QodeAssist.ccCustomLanguages";
|
||||
const char CA_ENABLE_CHAT_IN_BOTTOM_TOOLBAR[] = "QodeAssist.caEnableChatInBottomToolbar";
|
||||
const char CA_ENABLE_CHAT_IN_NAVIGATION_PANEL[] = "QodeAssist.caEnableChatInNavigationPanel";
|
||||
const char CA_USE_TOOLS[] = "QodeAssist.caUseTools";
|
||||
const char CA_ALLOW_FILE_SYSTEM_READ[] = "QodeAssist.caAllowFileSystemRead";
|
||||
|
||||
const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
|
||||
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
|
||||
|
||||
@ -75,6 +75,11 @@ QJsonObject ListProjectFilesTool::getDefinition(LLMCore::ToolSchemaFormat format
|
||||
return definition;
|
||||
}
|
||||
|
||||
LLMCore::ToolPermissions ListProjectFilesTool::requiredPermissions() const
|
||||
{
|
||||
return LLMCore::ToolPermission::FileSystemRead;
|
||||
}
|
||||
|
||||
QFuture<QString> ListProjectFilesTool::executeAsync(const QJsonObject &input)
|
||||
{
|
||||
Q_UNUSED(input)
|
||||
|
||||
@ -35,6 +35,8 @@ public:
|
||||
QString stringName() const override;
|
||||
QString description() const override;
|
||||
QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override;
|
||||
LLMCore::ToolPermissions requiredPermissions() const override;
|
||||
|
||||
QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override;
|
||||
|
||||
private:
|
||||
|
||||
@ -93,6 +93,11 @@ QJsonObject ReadProjectFileByNameTool::getDefinition(LLMCore::ToolSchemaFormat f
|
||||
return definition;
|
||||
}
|
||||
|
||||
LLMCore::ToolPermissions ReadProjectFileByNameTool::requiredPermissions() const
|
||||
{
|
||||
return LLMCore::ToolPermission::FileSystemRead;
|
||||
}
|
||||
|
||||
QFuture<QString> ReadProjectFileByNameTool::executeAsync(const QJsonObject &input)
|
||||
{
|
||||
return QtConcurrent::run([this, input]() -> QString {
|
||||
|
||||
@ -34,6 +34,8 @@ public:
|
||||
QString stringName() const override;
|
||||
QString description() const override;
|
||||
QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override;
|
||||
LLMCore::ToolPermissions requiredPermissions() const override;
|
||||
|
||||
QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override;
|
||||
|
||||
private:
|
||||
|
||||
@ -73,6 +73,11 @@ QJsonObject ReadVisibleFilesTool::getDefinition(LLMCore::ToolSchemaFormat format
|
||||
return definition;
|
||||
}
|
||||
|
||||
LLMCore::ToolPermissions ReadVisibleFilesTool::requiredPermissions() const
|
||||
{
|
||||
return LLMCore::ToolPermission::FileSystemRead;
|
||||
}
|
||||
|
||||
QFuture<QString> ReadVisibleFilesTool::executeAsync(const QJsonObject &input)
|
||||
{
|
||||
Q_UNUSED(input)
|
||||
|
||||
@ -34,6 +34,8 @@ public:
|
||||
QString stringName() const override;
|
||||
QString description() const override;
|
||||
QJsonObject getDefinition(LLMCore::ToolSchemaFormat format) const override;
|
||||
LLMCore::ToolPermissions requiredPermissions() const override;
|
||||
|
||||
QFuture<QString> executeAsync(const QJsonObject &input = QJsonObject()) override;
|
||||
|
||||
private:
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include "ToolsFactory.hpp"
|
||||
|
||||
#include "logger/Logger.hpp"
|
||||
#include <settings/GeneralSettings.hpp>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
@ -72,10 +73,39 @@ LLMCore::BaseTool *ToolsFactory::getToolByName(const QString &name) const
|
||||
QJsonArray ToolsFactory::getToolsDefinitions(LLMCore::ToolSchemaFormat format) const
|
||||
{
|
||||
QJsonArray toolsArray;
|
||||
const auto &settings = Settings::generalSettings();
|
||||
|
||||
for (auto it = m_tools.constBegin(); it != m_tools.constEnd(); ++it) {
|
||||
if (it.value()) {
|
||||
if (!it.value()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto requiredPerms = it.value()->requiredPermissions();
|
||||
bool hasPermission = true;
|
||||
|
||||
if (requiredPerms.testFlag(LLMCore::ToolPermission::FileSystemRead)) {
|
||||
if (!settings.allowFileSystemRead()) {
|
||||
hasPermission = false;
|
||||
}
|
||||
}
|
||||
|
||||
// if (requiredPerms.testFlag(LLMCore::ToolPermission::FileSystemWrite)) {
|
||||
// if (!settings.allowFileSystemWrite()) {
|
||||
// hasPermission = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (requiredPerms.testFlag(LLMCore::ToolPermission::NetworkAccess)) {
|
||||
// if (!settings.allowNetworkAccess()) {
|
||||
// hasPermission = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (hasPermission) {
|
||||
toolsArray.append(it.value()->getDefinition(format));
|
||||
} else {
|
||||
LOG_MESSAGE(
|
||||
QString("Tool '%1' skipped due to missing permissions").arg(it.value()->name()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user