Setting the Websearch base URL with the Config plugin is now possible

This commit is contained in:
Peer Schütt 2026-06-11 16:46:40 +02:00
parent 24217c2928
commit 623ffec4c7
6 changed files with 52 additions and 5 deletions

View File

@ -52,11 +52,19 @@ public partial class ToolSettingsDialog : SettingsDialogBase
return string.Format(T("{0} Default: {1}"), description, defaultValue);
}
private bool IsFieldDisabled(string fieldName) =>
this.toolDefinition?.Id.Equals(ToolSelectionRules.READ_WEB_PAGE_TOOL_ID, StringComparison.Ordinal) is true &&
private bool IsFieldDisabled(string fieldName)
{
if (this.toolDefinition?.Id.Equals(ToolSelectionRules.WEB_SEARCH_TOOL_ID, StringComparison.Ordinal) is true &&
fieldName.Equals("baseUrl", StringComparison.Ordinal) &&
ManagedConfiguration.TryGet(x => x.Tools, x => x.WebSearchBaseUrl, out var webSearchMeta) &&
webSearchMeta.IsLocked)
return true;
return this.toolDefinition?.Id.Equals(ToolSelectionRules.READ_WEB_PAGE_TOOL_ID, StringComparison.Ordinal) is true &&
fieldName.Equals("allowedPrivateHosts", StringComparison.Ordinal) &&
ManagedConfiguration.TryGet(x => x.Tools, x => x.ReadWebPageAllowedPrivateHosts, out var meta) &&
meta.IsLocked;
ManagedConfiguration.TryGet(x => x.Tools, x => x.ReadWebPageAllowedPrivateHosts, out var readWebPageMeta) &&
readWebPageMeta.IsLocked;
}
private string GetFieldPlaceholder(string fieldName, ToolSettingsFieldDefinition fieldDefinition) =>
string.IsNullOrWhiteSpace(this.GetValue(fieldName)) ? this.GetFieldDefaultValue(fieldName, fieldDefinition) : string.Empty;

View File

@ -269,6 +269,11 @@ CONFIG["SETTINGS"] = {}
-- ["read_web_page"] = "MEDIUM"
-- }
-- Configure the SearXNG instance URL used by the Web Search tool.
-- You can enter either the instance root URL or the /search endpoint.
-- CONFIG["SETTINGS"]["DataTools.WebSearchBaseUrl"] = "https://searxng.website/"
-- CONFIG["SETTINGS"]["DataTools.WebSearchBaseUrl.AllowUserOverride"] = false
-- Configure private or VPN hosts that the Read Web Page tool may access.
-- Public web pages do not need to be listed here.
-- Private hosts listed here still require a provider with HIGH confidence before any page content is sent to the model.

View File

@ -21,6 +21,11 @@ public sealed class DataTools(Expression<Func<Data, DataTools>>? configSelection
x => x.MinimumProviderConfidenceByToolId,
new Dictionary<string, string>(StringComparer.Ordinal));
public string WebSearchBaseUrl { get; set; } = ManagedConfiguration.Register<DataTools>(
configSelection,
x => x.WebSearchBaseUrl,
string.Empty);
public string ReadWebPageAllowedPrivateHosts { get; set; } = ManagedConfiguration.Register<DataTools>(
configSelection,
x => x.ReadWebPageAllowedPrivateHosts,

View File

@ -175,6 +175,9 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
// Config: minimum provider confidence per tool
ManagedConfiguration.TryProcessConfiguration(x => x.Tools, x => x.MinimumProviderConfidenceByToolId, this.Id, settingsTable, dryRun);
// Config: SearXNG base URL for the web search tool
ManagedConfiguration.TryProcessConfiguration(x => x.Tools, x => x.WebSearchBaseUrl, this.Id, settingsTable, dryRun);
// Config: private hosts allowed for the read web page tool
ManagedConfiguration.TryProcessConfiguration(x => x.Tools, x => x.ReadWebPageAllowedPrivateHosts, this.Id, settingsTable, dryRun);

View File

@ -249,6 +249,10 @@ public static partial class PluginFactory
if(ManagedConfiguration.IsConfigurationLeftOver(x => x.Tools, x => x.MinimumProviderConfidenceByToolId, AVAILABLE_PLUGINS))
wasConfigurationChanged = true;
// Check for the SearXNG base URL for the web search tool:
if(ManagedConfiguration.IsConfigurationLeftOver(x => x.Tools, x => x.WebSearchBaseUrl, AVAILABLE_PLUGINS))
wasConfigurationChanged = true;
// Check for private hosts allowed for the read web page tool:
if(ManagedConfiguration.IsConfigurationLeftOver(x => x.Tools, x => x.ReadWebPageAllowedPrivateHosts, AVAILABLE_PLUGINS))
wasConfigurationChanged = true;

View File

@ -5,6 +5,7 @@ namespace AIStudio.Tools.ToolCallingSystem;
public sealed class ToolSettingsService(SettingsManager settingsManager, RustService rustService)
{
private const string WEB_SEARCH_BASE_URL_FIELD = "baseUrl";
private const string READ_WEB_PAGE_ALLOWED_PRIVATE_HOSTS_FIELD = "allowedPrivateHosts";
public async Task<Dictionary<string, string>> GetSettingsAsync(ToolDefinition definition)
@ -15,6 +16,12 @@ public sealed class ToolSettingsService(SettingsManager settingsManager, RustSer
{
var fieldName = property.Key;
var fieldDefinition = property.Value;
if (IsWebSearchBaseUrlField(definition, fieldName))
{
values[fieldName] = settingsManager.ConfigurationData.Tools.WebSearchBaseUrl;
continue;
}
if (IsReadWebPageAllowedPrivateHostsField(definition, fieldName))
{
values[fieldName] = settingsManager.ConfigurationData.Tools.ReadWebPageAllowedPrivateHosts;
@ -87,6 +94,14 @@ public sealed class ToolSettingsService(SettingsManager settingsManager, RustSer
values.TryGetValue(fieldName, out var value);
value ??= string.Empty;
if (IsWebSearchBaseUrlField(definition, fieldName))
{
if (!IsWebSearchBaseUrlLocked())
settingsManager.ConfigurationData.Tools.WebSearchBaseUrl = value;
continue;
}
if (IsReadWebPageAllowedPrivateHostsField(definition, fieldName))
{
if (!IsReadWebPageAllowedPrivateHostsLocked())
@ -113,6 +128,13 @@ public sealed class ToolSettingsService(SettingsManager settingsManager, RustSer
await MessageBus.INSTANCE.SendMessage<object?>(null, Event.CONFIGURATION_CHANGED, null);
}
private static bool IsWebSearchBaseUrlField(ToolDefinition definition, string fieldName) =>
definition.Id.Equals(ToolSelectionRules.WEB_SEARCH_TOOL_ID, StringComparison.Ordinal) &&
fieldName.Equals(WEB_SEARCH_BASE_URL_FIELD, StringComparison.Ordinal);
private static bool IsWebSearchBaseUrlLocked() =>
ManagedConfiguration.TryGet(x => x.Tools, x => x.WebSearchBaseUrl, out var meta) && meta.IsLocked;
private static bool IsReadWebPageAllowedPrivateHostsField(ToolDefinition definition, string fieldName) =>
definition.Id.Equals(ToolSelectionRules.READ_WEB_PAGE_TOOL_ID, StringComparison.Ordinal) &&
fieldName.Equals(READ_WEB_PAGE_ALLOWED_PRIVATE_HOSTS_FIELD, StringComparison.Ordinal);