Files
AX-Copilot-Codex/src/AxCopilot/Services/OperationModePolicy.cs

44 lines
1.3 KiB
C#

using AxCopilot.Models;
namespace AxCopilot.Services;
public static class OperationModePolicy
{
public const string InternalMode = "internal";
public const string ExternalMode = "external";
public static string Normalize(string? mode)
{
var token = (mode ?? "").Trim().ToLowerInvariant();
return token == ExternalMode ? ExternalMode : InternalMode;
}
public static bool IsInternal(AppSettings? settings)
=> IsInternal(settings?.OperationMode);
public static bool IsInternal(string? mode)
=> string.Equals(Normalize(mode), InternalMode, StringComparison.OrdinalIgnoreCase);
public static bool IsBlockedAgentToolInInternalMode(string toolName, string? target)
{
if (string.Equals(toolName, "http_tool", StringComparison.OrdinalIgnoreCase))
return true;
if (string.Equals(toolName, "open_external", StringComparison.OrdinalIgnoreCase))
return IsExternalUrl(target);
return false;
}
public static bool IsExternalUrl(string? value)
{
if (string.IsNullOrWhiteSpace(value))
return false;
if (!Uri.TryCreate(value, UriKind.Absolute, out var uri))
return false;
return uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps;
}
}