mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 21:39:46 +00:00
Migration to use the new ERI client
This commit is contained in:
parent
5c4103f859
commit
c6050e6714
@ -1,4 +1,4 @@
|
|||||||
@using ERI_Client.V1
|
@using AIStudio.Tools.ERIClient.DataModel
|
||||||
<MudDialog>
|
<MudDialog>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues">
|
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues">
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
using AIStudio.Assistants.ERI;
|
||||||
using AIStudio.Settings;
|
using AIStudio.Settings;
|
||||||
using AIStudio.Settings.DataModel;
|
using AIStudio.Settings.DataModel;
|
||||||
|
using AIStudio.Tools.ERIClient;
|
||||||
|
using AIStudio.Tools.ERIClient.DataModel;
|
||||||
using AIStudio.Tools.Validation;
|
using AIStudio.Tools.Validation;
|
||||||
|
|
||||||
using ERI_Client.V1;
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
@ -43,7 +44,6 @@ public partial class DataSourceERI_V1Dialog : ComponentBase, ISecretId
|
|||||||
private string[] dataIssues = [];
|
private string[] dataIssues = [];
|
||||||
private string dataSecretStorageIssue = string.Empty;
|
private string dataSecretStorageIssue = string.Empty;
|
||||||
private string dataEditingPreviousInstanceName = string.Empty;
|
private string dataEditingPreviousInstanceName = string.Empty;
|
||||||
private HttpClient? httpClient;
|
|
||||||
private List<AuthMethod> availableAuthMethods = [];
|
private List<AuthMethod> availableAuthMethods = [];
|
||||||
private bool connectionTested;
|
private bool connectionTested;
|
||||||
private bool connectionSuccessfulTested;
|
private bool connectionSuccessfulTested;
|
||||||
@ -167,31 +167,38 @@ public partial class DataSourceERI_V1Dialog : ComponentBase, ISecretId
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.httpClient = new HttpClient
|
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(14));
|
||||||
|
var dataSource = new DataSourceERI_V1
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri($"{this.dataHostname}:{this.dataPort}"),
|
Hostname = this.dataHostname,
|
||||||
Timeout = TimeSpan.FromSeconds(5),
|
Port = this.dataPort
|
||||||
};
|
};
|
||||||
|
|
||||||
using (this.httpClient)
|
using var client = ERIClientFactory.Get(ERIVersion.V1, dataSource);
|
||||||
|
if(client is null)
|
||||||
{
|
{
|
||||||
var client = new Client(this.httpClient);
|
await this.form.Validate();
|
||||||
var authSchemes = await client.GetAuthMethodsAsync();
|
|
||||||
if (authSchemes is null)
|
Array.Resize(ref this.dataIssues, this.dataIssues.Length + 1);
|
||||||
{
|
this.dataIssues[^1] = "Failed to connect to the ERI v1 server. The server is not supported.";
|
||||||
await this.form.Validate();
|
return;
|
||||||
|
|
||||||
Array.Resize(ref this.dataIssues, this.dataIssues.Length + 1);
|
|
||||||
this.dataIssues[^1] = "Failed to connect to the ERI v1 server. The server did not respond.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.availableAuthMethods = authSchemes.Select(n => n.AuthMethod).ToList();
|
|
||||||
|
|
||||||
this.connectionTested = true;
|
|
||||||
this.connectionSuccessfulTested = true;
|
|
||||||
this.Logger.LogInformation("Connection to the ERI v1 server was successful tested.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var authSchemes = await client.GetAuthMethodsAsync(cts.Token);
|
||||||
|
if (!authSchemes.Successful)
|
||||||
|
{
|
||||||
|
await this.form.Validate();
|
||||||
|
|
||||||
|
Array.Resize(ref this.dataIssues, this.dataIssues.Length + 1);
|
||||||
|
this.dataIssues[^1] = authSchemes.Message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.availableAuthMethods = authSchemes.Data!.Select(n => n.AuthMethod).ToList();
|
||||||
|
|
||||||
|
this.connectionTested = true;
|
||||||
|
this.connectionSuccessfulTested = true;
|
||||||
|
this.Logger.LogInformation("Connection to the ERI v1 server was successful tested.");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user