w4c-workflows-api/Services/LanguageRegistry.cs

34 lines
1.3 KiB
C#

namespace w4c_workflows.Services;
/// <summary>Describes an executable language in the (extensible) runtime registry.</summary>
public sealed record LanguageInfo(string Id, string DisplayName, string DefaultFunction, string Extension);
/// <summary>
/// The set of languages the engine can execute. This is the single source of
/// truth for YAML validation and the <c>GET /api/languages</c> endpoint; the
/// worker maps each <see cref="LanguageInfo.Id"/> to an executor in step 7.
/// </summary>
public class LanguageRegistry
{
private readonly IReadOnlyList<LanguageInfo> _languages;
public LanguageRegistry()
{
_languages = new[]
{
new LanguageInfo("shell", "Shell", "main", ".sh"),
new LanguageInfo("javascript", "JavaScript", "handler", ".js"),
new LanguageInfo("typescript", "TypeScript", "handler", ".ts"),
new LanguageInfo("csharp", "C#", "Main", ".cs"),
new LanguageInfo("python", "Python", "main", ".py"),
new LanguageInfo("agent", "Agent", "run", ""),
};
}
public IReadOnlyList<LanguageInfo> All => _languages;
public bool IsKnown(string id) => _languages.Any(l => l.Id == id);
public LanguageInfo? Get(string id) => _languages.FirstOrDefault(l => l.Id == id);
}