using System.Text.Json; using System.Text.Json.Serialization; using YMhut.Box.Core.Plugins; namespace YMhut.Box.Core.Plugins.Runtime; public static class PluginRuntimeProtocol { public const string Version = "2"; public const string Ready = "ready"; public const string Ping = "ping"; public const string Pong = "pong"; public const string Launch = "launch"; public const string ShellStart = "shellStart"; public const string ShellInput = "shellInput"; public const string ShellOutput = "shellOutput"; public const string ShellExit = "shellExit"; public const string BridgeCall = "bridgeCall"; public const string Log = "log"; public const string Cancel = "cancel"; public const string Shutdown = "shutdown"; public const string Error = "error"; private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web) { WriteIndented = false, PropertyNameCaseInsensitive = true, Converters = { new JsonStringEnumConverter(), new JsonStringEnumConverter(), new JsonStringEnumConverter() } }; public static string Serialize(PluginRuntimeMessage message) { return JsonSerializer.Serialize(message, JsonOptions); } public static PluginRuntimeMessage? Deserialize(string line) { return JsonSerializer.Deserialize(line, JsonOptions); } } public sealed record PluginRuntimeMessage( string Type, string RequestId = "", string? Version = null, PluginRuntimeLaunchRequest? LaunchRequest = null, PluginRuntimeSession? Session = null, ShellCommandSpec? ShellCommand = null, ShellOutputEvent? ShellOutput = null, string? ShellInput = null, PluginBridgeRequest? BridgeRequest = null, PluginBridgeResponse? BridgeResponse = null, string? LogLevel = null, string? LogCategory = null, string? LogMessage = null, string? LogDetail = null, int? ExitCode = null, string? Error = null, string? SessionToken = null, string? Origin = null);