using System.Text.Json.Nodes; namespace XFEWorkflow.Abstractions; public static class WorkflowSdk { public const string CurrentVersion = "1.7.1"; } public interface IWorkflow { ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken); } public interface IWorkflowContext { string RunId { get; } JsonObject Inputs { get; } JsonObject Variables { get; } ValueTask InvokeAsync(string capabilityId, JsonObject inputs, CancellationToken cancellationToken = default); ValueTask InvokeWorkflowAsync(string workflowId, JsonObject inputs, CancellationToken cancellationToken = default); ValueTask ExecuteGraphAsync(GraphDefinition graph, CancellationToken cancellationToken = default) => throw new NotSupportedException("当前宿主不支持从 C# 执行图形,请使用 SDK 1.2 或更高版本"); ValueTask ExecuteWorkflowAsync(WorkflowDefinition workflow, JsonObject inputs, CancellationToken cancellationToken = default) => throw new NotSupportedException("封装节点需要 SDK 1.3 或更高版本"); ValueTask GetSecretAsync(string reference, CancellationToken cancellationToken = default); ValueTask InvokeHostAsync(string method, JsonObject parameters, CancellationToken cancellationToken = default); ValueTask LogAsync(string message, CancellationToken cancellationToken = default); } public interface ICapabilityInvoker { ValueTask InvokeAsync(string capabilityId, JsonObject inputs, IWorkflowContext context, CancellationToken cancellationToken); } public interface IWorkflowPlugin { void Register(IPluginRegistry registry); } public interface IPluginRegistry { void RegisterAction(CapabilityDescriptor descriptor, Func factory); void RegisterTrigger(CapabilityDescriptor descriptor, Func factory); void RegisterPage(PluginPageDescriptor descriptor) => throw new NotSupportedException("插件页面需要 SDK 1.7 或更高版本"); } public interface IWorkflowAction { ValueTask ExecuteAsync(JsonObject inputs, IWorkflowContext context, CancellationToken cancellationToken); } public interface IWorkflowTrigger { Task RunAsync(JsonObject parameters, IWorkflowContext context, Func emit, CancellationToken cancellationToken); } public sealed class CapabilityDescriptor { public string Id { get; set; } = ""; public string PluginId { get; set; } = ""; public string Name { get; set; } = ""; public string Category { get; set; } = "插件"; public string Description { get; set; } = ""; public bool IsTrigger { get; set; } public List Inputs { get; set; } = []; public List Outputs { get; set; } = []; public List ExecutionOutputs { get; set; } = ["next"]; public string? ExecutionResultPort { get; set; } public List ChildGraphs { get; set; } = []; public override string ToString() => Name; } public sealed class PluginManifest { public int SchemaVersion { get; set; } = 1; public int SdkMajorVersion { get; set; } = 1; public string SdkMinimumVersion { get; set; } = "1.0.0"; public string SdkMaximumVersionExclusive { get; set; } = "2.0.0"; public string Id { get; set; } = ""; public string Name { get; set; } = ""; public string Version { get; set; } = "1.0.0"; public string Description { get; set; } = ""; public string Author { get; set; } = ""; public string Assembly { get; set; } = ""; public string EntryType { get; set; } = ""; public List SupportedRids { get; set; } = []; public List Permissions { get; set; } = []; public List Dependencies { get; set; } = []; public List Capabilities { get; set; } = []; public List Pages { get; set; } = []; } /// Optional desktop extension. The main plugin entry stays platform independent; its view assembly is loaded only by the desktop host. public sealed class PluginPageDescriptor { public string Id { get; set; } = ""; public string PluginId { get; set; } = ""; public string Name { get; set; } = ""; public string Description { get; set; } = ""; public string IconGlyph { get; set; } = "\uE774"; public string Assembly { get; set; } = ""; public string EntryType { get; set; } = ""; } public sealed class PluginDependency { public string Id { get; set; } = ""; public string MinimumVersion { get; set; } = "1.0.0"; public string? MaximumVersionExclusive { get; set; } public string? ExactVersion { get; set; } public bool Accepts(string version) => (ExactVersion is null || ExactVersion == version) && SemanticVersion.Parse(version).CompareTo(SemanticVersion.Parse(MinimumVersion)) >= 0 && (MaximumVersionExclusive is null || SemanticVersion.Parse(version).CompareTo(SemanticVersion.Parse(MaximumVersionExclusive)) < 0); } public sealed class InstalledPlugin { public PluginManifest Manifest { get; set; } = new(); public bool Enabled { get; set; } = true; public bool PendingRemoval { get; set; } public string Directory { get; set; } = ""; public string Source { get; set; } = "本地导入"; public override string ToString() => $"{Manifest.Name} {Manifest.Version}"; } public interface ICodeWorkflowExecutor { ValueTask ExecuteAsync(string source, bool isNodeBody, string fileName, IWorkflowContext context, CancellationToken cancellationToken); }