feat: add ERP agent pet bridge and startup guide

This commit is contained in:
郎速科技
2026-08-14 14:28:28 +08:00
parent a803070819
commit 4c08f4c948
252 changed files with 134752 additions and 72 deletions
@@ -0,0 +1,62 @@
using System.Text.Json;
namespace Lskj.AgentPet.Host.Core.WebViewHost;
public enum HostWindowCommand
{
None = 0,
Close = 1
}
/// <summary>
/// Parses the deliberately tiny set of window-management messages accepted
/// from the embedded, origin-bound pet page. Business messages continue to be
/// handled by <see cref="WebMessageCoordinator"/>.
/// </summary>
public static class HostWindowCommandParser
{
private const int MaximumMessageCharacters = 1024;
public static bool TryParse(string? json, out HostWindowCommand command)
{
command = HostWindowCommand.None;
if (string.IsNullOrWhiteSpace(json)
|| json.Length > MaximumMessageCharacters)
return false;
try
{
using JsonDocument document = JsonDocument.Parse(json, new JsonDocumentOptions
{
AllowTrailingCommas = false,
CommentHandling = JsonCommentHandling.Disallow,
MaxDepth = 4
});
JsonElement root = document.RootElement;
if (root.ValueKind != JsonValueKind.Object) return false;
int propertyCount = 0;
string? type = null;
HashSet<string> names = new(StringComparer.Ordinal);
foreach (JsonProperty property in root.EnumerateObject())
{
propertyCount++;
if (!names.Add(property.Name)
|| !string.Equals(property.Name, "type", StringComparison.Ordinal)
|| property.Value.ValueKind != JsonValueKind.String)
return false;
type = property.Value.GetString();
}
if (propertyCount != 1
|| !string.Equals(type, "lserp.window.close", StringComparison.Ordinal))
return false;
command = HostWindowCommand.Close;
return true;
}
catch (JsonException)
{
return false;
}
}
}
File diff suppressed because it is too large Load Diff