Initial commit to new repository
This commit is contained in:
43
src/AxCopilot/Services/OperationModePolicy.cs
Normal file
43
src/AxCopilot/Services/OperationModePolicy.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user