Added a semantic search tool (#1005)
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-09-27 16:26:52 +02:00
1 parent 4baf21656a
commit 1eaca9b12f
91 files changed
+4248 -487

No files matched your search

@@ -111,11 +111,6 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
/// </remarks>
private static readonly string[] TIME_RANGES = [TIME_RANGE_DAY, TIME_RANGE_WEEK, TIME_RANGE_MONTH, TIME_RANGE_YEAR];
/// <summary>
/// How much of a wrongly passed argument an error message repeats back to the model.
/// </summary>
private const int MAX_ARGUMENT_ECHO_LENGTH = 40;
public string ImplementationKey => ToolSelectionRules.WEB_SEARCH_TOOL_ID;
/// <inheritdoc />
@@ -826,95 +821,27 @@ public sealed class WebSearchTool(IEnumerable<IWebSearchBackend> backends, WebPa
/// <summary>
/// Reads the search query, the one argument the model always has to pass.
/// </summary>
internal static string ReadQuery(JsonElement arguments)
{
var query = ReadOptionalString(arguments, QUERY_ARGUMENT, whenLeftOut: null);
if (string.IsNullOrWhiteSpace(query))
throw new ArgumentException($"Missing required argument '{QUERY_ARGUMENT}'.");
return query;
}
internal static string ReadQuery(JsonElement arguments) => ToolArgumentReader.ReadRequiredString(arguments, QUERY_ARGUMENT);
/// <summary>
/// Reads the language tag the model asked for, or null for the configured language.
/// </summary>
internal static string? ReadLanguage(JsonElement arguments) => ReadOptionalString(arguments, LANGUAGE_ARGUMENT, "to use the configured language");
internal static string? ReadLanguage(JsonElement arguments) => ToolArgumentReader.ReadOptionalString(arguments, LANGUAGE_ARGUMENT, "to use the configured language");
/// <summary>
/// Reads the time range the model asked for, or null for no restriction.
/// </summary>
internal static string? ReadTimeRange(JsonElement arguments)
{
if (!TryGetArgument(arguments, TIME_RANGE_ARGUMENT, out var value))
return null;
var timeRange = value.ValueKind is JsonValueKind.String ? value.GetString()?.Trim() : null;
if (timeRange is null || !TIME_RANGES.Contains(timeRange, StringComparer.Ordinal))
throw InvalidArgument(TIME_RANGE_ARGUMENT, value, $"one of {string.Join(", ", TIME_RANGES)}", "to search without a time restriction");
return timeRange;
}
internal static string? ReadTimeRange(JsonElement arguments) => ToolArgumentReader.ReadOptionalChoice(arguments, TIME_RANGE_ARGUMENT, TIME_RANGES, "to search without a time restriction");
/// <summary>
/// Reads the result page the model asked for, or null for the first one.
/// </summary>
internal static int? ReadPage(JsonElement arguments) => ReadOptionalPositiveInt(arguments, PAGE_ARGUMENT, "to get the first page");
internal static int? ReadPage(JsonElement arguments) => ToolArgumentReader.ReadOptionalPositiveInt(arguments, PAGE_ARGUMENT, "to get the first page");
/// <summary>
/// Reads how many results the model asked for, or null for the configured number.
/// </summary>
internal static int? ReadLimit(JsonElement arguments) => ReadOptionalPositiveInt(arguments, LIMIT_ARGUMENT, "to get as many results as configured");
/// <summary>
/// Looks up an argument, treating null the same as leaving it out.
/// </summary>
private static bool TryGetArgument(JsonElement arguments, string propertyName, out JsonElement value) =>
arguments.TryGetProperty(propertyName, out value) && value.ValueKind is not JsonValueKind.Null;
private static string? ReadOptionalString(JsonElement arguments, string propertyName, string? whenLeftOut)
{
if (!TryGetArgument(arguments, propertyName, out var value))
return null;
if (value.ValueKind is not JsonValueKind.String)
throw InvalidArgument(propertyName, value, "a string", whenLeftOut);
return value.GetString()?.Trim();
}
private static int? ReadOptionalPositiveInt(JsonElement arguments, string propertyName, string whenLeftOut)
{
if (!TryGetArgument(arguments, propertyName, out var value))
return null;
if (value.ValueKind is not JsonValueKind.Number || !value.TryGetInt32(out var intValue) || intValue <= 0)
throw InvalidArgument(propertyName, value, "a positive integer", whenLeftOut);
return intValue;
}
/// <summary>
/// Builds the error a model gets for an argument it passed wrongly.
/// </summary>
/// <remarks>
/// The model reads this and tries again, so it says what arrived, what would have been right,
/// and, for an optional argument, that leaving it out is always an option. A model which
/// believes the argument has to be there otherwise keeps trying placeholders, and every attempt
/// costs one of the tool calls an answer may make.
/// </remarks>
/// <param name="propertyName">The argument.</param>
/// <param name="value">What the model passed, as it arrived.</param>
/// <param name="expectation">What the argument must be, completing "must be ...".</param>
/// <param name="whenLeftOut">What happens without the argument, completing "Leave it out ...", or null for a required one.</param>
private static ArgumentException InvalidArgument(string propertyName, JsonElement value, string expectation, string? whenLeftOut)
{
var receivedValue = value.GetRawText();
if (receivedValue.Length > MAX_ARGUMENT_ECHO_LENGTH)
receivedValue = $"{receivedValue[..MAX_ARGUMENT_ECHO_LENGTH]}...";
var message = $"Argument '{propertyName}' must be {expectation}, but was {receivedValue}.";
return new ArgumentException(whenLeftOut is null ? message : $"{message} Leave it out {whenLeftOut}.");
}
internal static int? ReadLimit(JsonElement arguments) => ToolArgumentReader.ReadOptionalPositiveInt(arguments, LIMIT_ARGUMENT, "to get as many results as configured");
private static string FormatQueryForLog(string query)
{