refactor: split node agent and Go control plane
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace WxAgent.Core;
|
||||
|
||||
public sealed record UiNodeSnapshot(
|
||||
string ControlType,
|
||||
string Name,
|
||||
string AutomationId,
|
||||
bool IsEnabled,
|
||||
string Bounds,
|
||||
IReadOnlyList<UiNodeSnapshot> Children);
|
||||
|
||||
public static class UiSnapshotSanitizer
|
||||
{
|
||||
private static readonly HashSet<string> SafeAutomationIds = new(StringComparer.Ordinal)
|
||||
{
|
||||
"MainView",
|
||||
"MainView.main_tabbar",
|
||||
"MainView.main_tabbar.tabbar_setting",
|
||||
"session_list",
|
||||
"chat_message_page",
|
||||
"chat_message_list",
|
||||
"chat_message_list.qt_scrollarea_viewport.chat_bubble_item_view",
|
||||
"chat_input_field",
|
||||
"chat_input_field.qt_scrollarea_viewport",
|
||||
"tool_bar_accessible"
|
||||
};
|
||||
|
||||
private static readonly HashSet<string> SafeSearchLabels = new(StringComparer.Ordinal)
|
||||
{
|
||||
"联系人", "群聊", "功能", "聊天记录", "网络搜索", "搜一搜", "返回",
|
||||
"更多联系人", "更多群聊", "查看更多联系人", "查看更多群聊", "查看全部", "显示全部"
|
||||
};
|
||||
|
||||
public static string SanitizeName(string? value) => Sanitize(value, SafeSearchLabels, "text");
|
||||
|
||||
public static string SanitizeAutomationId(string? value) => Sanitize(value, SafeAutomationIds, "id");
|
||||
|
||||
private static string Sanitize(string? value, HashSet<string> allowList, string label)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value) || allowList.Contains(value))
|
||||
{
|
||||
return value ?? string.Empty;
|
||||
}
|
||||
|
||||
var bytes = SHA256.HashData(Encoding.UTF8.GetBytes(value));
|
||||
return $"[{label}:{value.Length}:{Convert.ToHexString(bytes.AsSpan(0, 4)).ToLowerInvariant()}]";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user