AI-Studio/app/MindWork AI Studio/Tools/ToolCallingSystem/ToolExecutionModels.cs
Peer Schütt 0b2ce886c5 Key fixes include:
Prevented OS credentials from reaching public hosts or cross-origin redirects.
Preserved Responses API reasoning items across tool rounds.
Fixed nullable tool-call handling and omitted unsupported null request properties.
Propagated cancellation correctly.
Removed tool argument values from logs and tool results from persisted traces.
Added settings validation, clearable optional enums, managed-confidence validation, and safe fallback behavior.
Added tool-definition schema and duplicate validation.
Fixed documentation JSON, changelog regressions, typos, trailing whitespace, and unused Anthropic code.
2026-07-15 11:31:11 +02:00

108 lines
2.7 KiB
C#

using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using AIStudio.Provider;
using AIStudio.Settings;
namespace AIStudio.Tools.ToolCallingSystem;
public sealed class ToolExecutionContext
{
public required ToolDefinition Definition { get; init; }
public required SettingsManager SettingsManager { get; init; }
public required IReadOnlyDictionary<string, string> SettingsValues { get; init; }
public ConfidenceLevel ProviderConfidence { get; init; } = ConfidenceLevel.UNKNOWN;
}
public sealed class ToolExecutionResult
{
public string? TextContent { get; init; }
public JsonNode? JsonContent { get; init; }
public string ToModelContent()
{
if (this.JsonContent is not null)
return this.JsonContent.ToJsonString();
return this.TextContent ?? string.Empty;
}
}
public sealed class ToolExecutionBlockedException(string message) : Exception(message);
public enum ToolInvocationTraceStatus
{
NONE = 0,
SUCCESS,
ERROR,
BLOCKED,
}
public sealed class ToolInvocationTrace
{
public int Order { get; set; }
public string ToolId { get; set; } = string.Empty;
public string ToolName { get; set; } = string.Empty;
public string ToolIcon { get; set; } = Icons.Material.Filled.Build;
public string ToolCallId { get; set; } = string.Empty;
public ToolInvocationTraceStatus Status { get; set; } = ToolInvocationTraceStatus.NONE;
public bool WasExecuted { get; set; }
public string StatusMessage { get; set; } = string.Empty;
public Dictionary<string, string> Arguments { get; set; } = [];
[JsonIgnore]
public string Result { get; set; } = string.Empty;
}
public sealed class ToolRuntimeStatus
{
public bool IsRunning { get; set; }
public List<string> ToolNames { get; set; } = [];
public string Message => this.ToolNames.Count switch
{
0 => string.Empty,
1 => $"Using tool: {this.ToolNames[0]}",
_ => $"Using tools: {string.Join(", ", this.ToolNames)}",
};
}
public sealed class ToolConfigurationState
{
public bool IsConfigured { get; init; }
public List<string> MissingRequiredFields { get; init; } = [];
public string Message { get; init; } = string.Empty;
}
public sealed class ToolCatalogItem
{
public required ToolDefinition Definition { get; init; }
public required IToolImplementation Implementation { get; init; }
public required ToolConfigurationState ConfigurationState { get; init; }
public ConfidenceLevel MinimumProviderConfidence { get; init; } = ConfidenceLevel.NONE;
}
public sealed class ToolSelectionState
{
public HashSet<string> SelectedToolIds { get; init; } = [];
}