Added icons to visualize model capabilities to the provider dropdown menu (#829)
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
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

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
Peer HogeterpandThorsten Sommer authored and GitHub committed 2026-07-04 18:28:52 +02:00
1 parent a5a94a07d4
commit 431f0b78d8
15 files changed
+807 -63

No files matched your search

@@ -0,0 +1,96 @@
using System.Text.Json;
namespace AIStudio.Provider;
/// <summary>
/// Parses the provider-specific JSON fragment stored in <see cref="IProvider.AdditionalJsonApiParameters"/>.
/// </summary>
/// <remarks>
/// The provider settings UI stores only the body of a JSON object, such as
/// <c>"temperature": 0.5</c>. This parser wraps that fragment in curly braces,
/// parses it as JSON, and converts it to regular CLR dictionaries, lists, and
/// primitive values so request builders and feature detectors can inspect it.
/// </remarks>
public static class AdditionalApiParametersParser
{
/// <summary>
/// Try to parse an additional-API-parameters JSON fragment into a dictionary.
/// </summary>
/// <param name="additionalJsonApiParameters">The JSON object body without the surrounding curly braces.</param>
/// <param name="parameters">The parsed parameters if parsing succeeds; otherwise an empty dictionary.</param>
/// <param name="errorMessage">The JSON parsing error message if parsing fails; otherwise <see langword="null"/>.</param>
/// <returns><see langword="true"/> if the fragment is empty or valid JSON; otherwise <see langword="false"/>.</returns>
public static bool TryParse(string additionalJsonApiParameters, out IDictionary<string, object> parameters, out string? errorMessage)
{
parameters = new Dictionary<string, object>();
errorMessage = null;
if (string.IsNullOrWhiteSpace(additionalJsonApiParameters))
return true;
try
{
// The UI stores only the object body, so wrap it before parsing.
using var jsonDoc = JsonDocument.Parse($"{{{additionalJsonApiParameters}}}");
parameters = ConvertToDictionary(jsonDoc.RootElement);
return true;
}
catch (JsonException ex)
{
errorMessage = ex.Message;
return false;
}
}
/// <summary>
/// Remove keys from a parsed parameter dictionary using case-insensitive matching.
/// </summary>
/// <param name="parameters">The parsed parameter dictionary to mutate.</param>
/// <param name="keysToRemove">The parameter names that should be removed.</param>
/// <returns>The same dictionary instance after the matching keys were removed.</returns>
public static IDictionary<string, object> RemoveKeys(IDictionary<string, object> parameters, IEnumerable<string> keysToRemove)
{
var removeSet = new HashSet<string>(keysToRemove, StringComparer.OrdinalIgnoreCase);
if (removeSet.Count is 0)
return parameters;
foreach (var key in parameters.Keys.ToList())
if (removeSet.Contains(key))
parameters.Remove(key);
return parameters;
}
/// <summary>
/// Convert a JSON object element into a dictionary of recursively converted CLR values.
/// </summary>
/// <param name="element">The JSON object element to convert.</param>
/// <returns>A dictionary containing all JSON object properties.</returns>
private static IDictionary<string, object> ConvertToDictionary(JsonElement element)
{
return element.EnumerateObject()
.ToDictionary<JsonProperty, string, object>(
p => p.Name,
p => ConvertJsonValue(p.Value) ?? string.Empty
);
}
/// <summary>
/// Convert a JSON value to the closest CLR representation used by provider request objects.
/// </summary>
/// <param name="element">The JSON element to convert.</param>
/// <returns>A string, number, boolean, dictionary, list, or empty string for unsupported/null values.</returns>
private static object? ConvertJsonValue(JsonElement element) => element.ValueKind switch
{
JsonValueKind.String => element.GetString(),
JsonValueKind.Number => element.TryGetInt32(out var i) ? i :
element.TryGetInt64(out var l) ? l :
element.TryGetDouble(out var d) ? d :
element.GetDecimal(),
JsonValueKind.True or JsonValueKind.False => element.GetBoolean(),
JsonValueKind.Null => string.Empty,
JsonValueKind.Object => ConvertToDictionary(element),
JsonValueKind.Array => element.EnumerateArray().Select(ConvertJsonValue).ToList(),
_ => string.Empty,
};
}
@@ -1191,42 +1191,15 @@ public abstract class BaseProvider : IProvider, ISecretId
protected IDictionary<string, object> ParseAdditionalApiParameters(
params string[] keysToRemove)
{
if(string.IsNullOrWhiteSpace(this.AdditionalJsonApiParameters))
return new Dictionary<string, object>();
try
if (!AdditionalApiParametersParser.TryParse(this.AdditionalJsonApiParameters, out var apiParameters, out var errorMessage))
{
// Wrap the user-provided parameters in curly brackets to form a valid JSON object:
var json = $"{{{this.AdditionalJsonApiParameters}}}";
var jsonDoc = JsonSerializer.Deserialize<JsonElement>(json, JSON_SERIALIZER_OPTIONS);
var dict = ConvertToDictionary(jsonDoc);
// Some keys are always removed because we set them:
var removeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
if (keysToRemove.Length > 0)
removeSet.UnionWith(keysToRemove);
removeSet.Add("stream");
removeSet.Add("model");
removeSet.Add("messages");
// Remove the specified keys (case-insensitive):
if (removeSet.Count > 0)
{
foreach (var key in dict.Keys.ToList())
{
if (removeSet.Contains(key))
dict.Remove(key);
}
}
return dict;
}
catch (JsonException ex)
{
this.logger.LogError("Failed to parse additional API parameters: {ExceptionMessage}", ex.Message);
this.logger.LogError("Failed to parse additional API parameters: {ExceptionMessage}", errorMessage);
return new Dictionary<string, object>();
}
// Some keys are always removed because AI Studio sets them itself.
var reservedKeys = keysToRemove.Concat(["stream", "model", "messages"]);
return AdditionalApiParametersParser.RemoveKeys(apiParameters, reservedKeys);
}
protected static bool TryPopIntParameter(IDictionary<string, object> parameters, string key, out int value)
@@ -1308,27 +1281,4 @@ public abstract class BaseProvider : IProvider, ISecretId
return true;
}
private static IDictionary<string, object> ConvertToDictionary(JsonElement element)
{
return element.EnumerateObject()
.ToDictionary<JsonProperty, string, object>(
p => p.Name,
p => ConvertJsonValue(p.Value) ?? string.Empty
);
}
private static object? ConvertJsonValue(JsonElement element) => element.ValueKind switch
{
JsonValueKind.String => element.GetString(),
JsonValueKind.Number => element.TryGetInt32(out var i) ? i :
element.TryGetInt64(out var l) ? l :
element.TryGetDouble(out var d) ? d :
element.GetDecimal(),
JsonValueKind.True or JsonValueKind.False => element.GetBoolean(),
JsonValueKind.Null => string.Empty,
JsonValueKind.Object => ConvertToDictionary(element),
JsonValueKind.Array => element.EnumerateArray().Select(ConvertJsonValue).ToList(),
_ => string.Empty,
};
}
@@ -71,15 +71,20 @@ public enum Capability
VIDEO_OUTPUT,
/// <summary>
/// The AI model can perform reasoning tasks.
/// The AI model can perform reasoning tasks. You can enable reasoning optionally, but it is disabled by default.
/// </summary>
OPTIONAL_REASONING,
/// <summary>
/// The AI model always performs reasoning.
/// The AI model always performs reasoning. There is no option to disable reasoning.
/// </summary>
ALWAYS_REASONING,
/// <summary>
/// The AI model performs optional reasoning, but it is enabled by default.
/// </summary>
REASONING_BY_DEFAULT,
/// <summary>
/// The AI model can embed information or data.
/// </summary>
@@ -0,0 +1,27 @@
namespace AIStudio.Provider;
/// <summary>
/// Describes whether the provider selection should show the reasoning capability icon.
/// </summary>
public enum ReasoningIndicatorState
{
/// <summary>
/// Do not show a reasoning indicator for the configured provider.
/// </summary>
NONE,
/// <summary>
/// Show that the selected model always performs reasoning.
/// </summary>
ALWAYS_ON,
/// <summary>
/// Show that reasoning is enabled by the provider or model default.
/// </summary>
DEFAULT_ON,
/// <summary>
/// Show that reasoning was explicitly enabled through the provider settings.
/// </summary>
CONFIGURED,
}