stabilize

This commit is contained in:
2026-02-10 23:25:42 +03:00
parent d9cc66e35c
commit 091565f020
10 changed files with 664 additions and 102 deletions

View File

@@ -1,5 +1,7 @@
using System.Reflection;
using System.Text.Json;
using System.Collections.Generic;
using System.IO;
using Scalar.AspNetCore;
// Ensure S8n.Components.Packages assembly is loaded
@@ -41,6 +43,47 @@ app.MapGet("/weatherforecast", () =>
})
.WithName("GetWeatherForecast");
// Component registry endpoint
app.MapGet("/api/components", () =>
{
var components = new List<ComponentDefinition>();
var componentsPath = Path.Combine(Directory.GetCurrentDirectory(), "..", "components");
if (!Directory.Exists(componentsPath))
{
// Fallback to absolute path from workspace root
componentsPath = Path.Combine(Directory.GetCurrentDirectory(), "components");
}
if (Directory.Exists(componentsPath))
{
var jsonFiles = Directory.GetFiles(componentsPath, "*.json", SearchOption.AllDirectories);
foreach (var file in jsonFiles)
{
try
{
var json = File.ReadAllText(file);
var component = JsonSerializer.Deserialize<ComponentDefinition>(json, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
if (component != null)
{
components.Add(component);
}
}
catch (Exception ex)
{
// Log error but continue
Console.WriteLine($"Error reading component file {file}: {ex.Message}");
}
}
}
return Results.Ok(components);
})
.WithName("GetComponents");
// Runtime execution endpoint
app.MapPost("/api/runtime/execute", (RuntimeRequest request) =>
{
@@ -164,3 +207,35 @@ record RuntimeResponse
public object? Outputs { get; set; }
public string? Error { get; set; }
}
record ComponentDefinition
{
public string Code { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string Icon { get; set; } = string.Empty;
public List<ComponentInput> Inputs { get; set; } = new();
public List<ComponentOutput> Outputs { get; set; } = new();
public string Source { get; set; } = string.Empty;
public string Class { get; set; } = string.Empty;
public List<string> Methods { get; set; } = new();
public string Gui { get; set; } = string.Empty;
public string Category { get; set; } = string.Empty;
public List<string> Tags { get; set; } = new();
}
record ComponentInput
{
public string Name { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public List<string>? Enum { get; set; }
public bool Required { get; set; } = true;
}
record ComponentOutput
{
public string Name { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
}