Skip to content

Commit 85f42f5

Browse files
committed
Refactor tool/plugin loading to use dynamic API data
- Replace static tool/plugin lists with dynamic loading from FlowSynx API - Update SearchablePluginsList to use PluginsFullDetailsList* - Make IToolRegistry.GetAll async and accept CancellationToken - Refactor ToolRegistry to fetch and log plugin data from API - Update WorkflowNodeProperties to load tools asynchronously - Bump FlowSynx.Client.AspNetCore to v1.3.12 #97
1 parent 4d8cd8e commit 85f42f5

5 files changed

Lines changed: 69 additions & 29 deletions

File tree

src/Components/Pages/Workflows/SearchablePluginsList.razor

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@
138138
FlowSynxClient.SetAuthenticationStrategy(
139139
new FlowSynx.Client.Authentication.BearerTokenAuthStrategy(token));
140140

141-
var request = new FlowSynx.Client.Messages.Requests.Plugins.PluginsListRequest
141+
var request = new FlowSynx.Client.Messages.Requests.Plugins.PluginsFullDetailsListRequest
142142
{
143143
Page = 1,
144144
PageSize = int.MaxValue
145145
};
146146

147-
var result = await FlowSynxClient.Plugins.ListAsync(request, cancellationToken);
147+
var result = await FlowSynxClient.Plugins.PluginsFullDetailsListAsync(request, cancellationToken);
148148

149149
if (result.StatusCode != 200 || !result.Payload.Succeeded)
150150
{
@@ -158,10 +158,11 @@
158158
{
159159
Type = g.Key,
160160
Description = g.FirstOrDefault()?.Description,
161-
Versions = g.Select(x => x.Version)
162-
.Distinct()
163-
.OrderByDescending(v => v)
164-
.ToList()
161+
Versions = g
162+
.SelectMany(x => x.Versions)
163+
.Distinct()
164+
.OrderByDescending(v => v)
165+
.ToList()
165166
})
166167
.ToList();
167168
}

src/Components/Pages/Workflows/WorkflowNodeProperties.razor

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@using MudBlazor
1+
@using Console.Models
2+
@using MudBlazor
23
@using System.Text.Json
34
@inject IToolRegistry ToolRegistry
45

@@ -256,7 +257,7 @@
256257
Placeholder="Select allowed tools"
257258
HelperText="These tools are allowed"
258259
Variant="Variant.Filled">
259-
@foreach (var tool in ToolRegistry.GetAll())
260+
@foreach (var tool in AvailableTools)
260261
{
261262
<MudSelectItem Value="@tool.Name">
262263
<MudText Typo="Typo.body1">@tool.Name</MudText>
@@ -276,7 +277,7 @@
276277
Placeholder="Select denied tools"
277278
HelperText="These tools are denied"
278279
Variant="Variant.Filled">
279-
@foreach (var tool in ToolRegistry.GetAll())
280+
@foreach (var tool in AvailableTools)
280281
{
281282
<MudSelectItem Value="@tool.Name">
282283
<MudText Typo="Typo.body1">@tool.Name</MudText>
@@ -556,6 +557,7 @@
556557
private string _newParamKey;
557558
private string _newParamValue;
558559
private bool IsProcessing = false;
560+
private List<ToolDescriptor> AvailableTools = new();
559561

560562
private string Dependencies
561563
{
@@ -581,7 +583,7 @@
581583
RunOnFailure.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList();
582584
}
583585

584-
protected override void OnInitialized()
586+
protected override async Task OnInitializedAsync()
585587
{
586588
SelectedTask.Position ??= new WorkflowTaskPosition(0, 0);
587589

@@ -630,6 +632,8 @@
630632
};
631633

632634
Dependencies = SelectedTask != null ? string.Join(',', SelectedTask.FlowControl.Dependencies) : string.Empty;
635+
636+
AvailableTools = await GetAvailableToolsAsync();
633637
}
634638

635639
private void Cancel()
@@ -703,7 +707,11 @@
703707
SelectedTask.FlowControl.ConditionalBranches.Remove(branch);
704708
}
705709

706-
private List<string> AvailableTools => ToolRegistry.GetAll().Select(t => t.Name).OrderBy(x => x).ToList();
710+
private async Task<List<ToolDescriptor>> GetAvailableToolsAsync()
711+
{
712+
var result = await ToolRegistry.GetAll(CancellationToken.None);
713+
return result.OrderBy(x => x.Name).ToList();
714+
}
707715

708716
public enum ErrorStrategy
709717
{

src/Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<ItemGroup>
2323
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
24-
<PackageReference Include="FlowSynx.Client.AspNetCore" Version="1.3.11" />
24+
<PackageReference Include="FlowSynx.Client.AspNetCore" Version="1.3.12" />
2525
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.1" />
2626
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.1" />
2727
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.15.0" />

src/Services/IToolRegistry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ namespace Console.Services;
44

55
public interface IToolRegistry
66
{
7-
IReadOnlyCollection<ToolDescriptor> GetAll();
7+
Task<IReadOnlyCollection<ToolDescriptor>> GetAll(CancellationToken cancellationToken);
88
}

src/Services/ToolRegistry.cs

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,55 @@
11
using Console.Models;
2+
using FlowSynx.Client;
23

34
namespace Console.Services;
45

56
public class ToolRegistry : IToolRegistry
67
{
7-
private readonly List<ToolDescriptor> _tools = new()
8+
private readonly IFlowSynxClient _flowSynxClient;
9+
private readonly IAccessTokenProvider _tokenProvider;
10+
private readonly ILogger<ToolRegistry> _logger;
11+
12+
public ToolRegistry(
13+
IFlowSynxClient flowSynxClient,
14+
IAccessTokenProvider tokenProvider,
15+
ILogger<ToolRegistry> logger)
16+
{
17+
_flowSynxClient = flowSynxClient;
18+
_tokenProvider = tokenProvider;
19+
_logger = logger;
20+
}
21+
22+
public async Task<IReadOnlyCollection<ToolDescriptor>> GetAll(CancellationToken cancellationToken)
823
{
9-
new ToolDescriptor(
10-
Name: "FlowSynx.Storage.Local",
11-
Description: "Reads and writes files to local or mounted file systems. Supports directory traversal, file watching, and bulk file operations."
12-
),
13-
new ToolDescriptor(
14-
Name: "FlowSynx.Data.Json",
15-
Description: "Loads and parses local JSON files. Supports transformation, extraction, and mapping of hierarchical data structures in workflows."
16-
),
17-
new ToolDescriptor(
18-
Name: "FlowSynx.Data.Csv",
19-
Description: "Reads and writes CSV files, enabling easy batch data import/export operations and integration with spreadsheet-based data workflows."
20-
)
21-
};
22-
23-
public IReadOnlyCollection<ToolDescriptor> GetAll() => _tools.AsReadOnly();
24+
try
25+
{
26+
var token = await _tokenProvider.GetAccessTokenAsync();
27+
_flowSynxClient.SetAuthenticationStrategy(
28+
new FlowSynx.Client.Authentication.BearerTokenAuthStrategy(token));
29+
30+
var request = new FlowSynx.Client.Messages.Requests.Plugins.PluginsFullDetailsListRequest
31+
{
32+
Page = 1,
33+
PageSize = int.MaxValue
34+
};
35+
36+
var result = await _flowSynxClient.Plugins.PluginsFullDetailsListAsync(request, cancellationToken);
37+
38+
if (result.StatusCode != 200 || !result.Payload.Succeeded)
39+
{
40+
_logger.LogError("Failed to load plugins");
41+
return new List<ToolDescriptor>();
42+
}
43+
44+
return result.Payload.Data
45+
.GroupBy(p => p.Type)
46+
.Select(g => new ToolDescriptor(g.Key, g.FirstOrDefault()?.Description))
47+
.ToList();
48+
}
49+
catch (Exception ex)
50+
{
51+
_logger.LogError(ex, ex.Message);
52+
return new List<ToolDescriptor>();
53+
}
54+
}
2455
}

0 commit comments

Comments
 (0)