mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-07-04 06:42:56 +00:00
Improved enterprise service (#493)
This commit is contained in:
parent
fcf511cea8
commit
6979a73e5c
@ -13,10 +13,6 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
|
|||||||
[Inject]
|
[Inject]
|
||||||
protected MessageBus MessageBus { get; init; } = null!;
|
protected MessageBus MessageBus { get; init; } = null!;
|
||||||
|
|
||||||
[Inject]
|
|
||||||
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
|
||||||
private ILogger<MSGComponentBase> Logger { get; init; } = null!;
|
|
||||||
|
|
||||||
private ILanguagePlugin Lang { get; set; } = PluginFactory.BaseLanguage;
|
private ILanguagePlugin Lang { get; set; } = PluginFactory.BaseLanguage;
|
||||||
|
|
||||||
#region Overrides of ComponentBase
|
#region Overrides of ComponentBase
|
||||||
@ -45,19 +41,22 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
|
|||||||
|
|
||||||
public async Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data)
|
public async Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data)
|
||||||
{
|
{
|
||||||
switch (triggeredEvent)
|
await this.InvokeAsync(async () =>
|
||||||
{
|
{
|
||||||
case Event.COLOR_THEME_CHANGED:
|
switch (triggeredEvent)
|
||||||
this.StateHasChanged();
|
{
|
||||||
break;
|
case Event.COLOR_THEME_CHANGED:
|
||||||
|
this.StateHasChanged();
|
||||||
|
break;
|
||||||
|
|
||||||
case Event.PLUGINS_RELOADED:
|
case Event.PLUGINS_RELOADED:
|
||||||
this.Lang = await this.SettingsManager.GetActiveLanguagePlugin();
|
this.Lang = await this.SettingsManager.GetActiveLanguagePlugin();
|
||||||
await this.InvokeAsync(this.StateHasChanged);
|
await this.InvokeAsync(this.StateHasChanged);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.ProcessIncomingMessage(sendingComponent, triggeredEvent, data);
|
await this.ProcessIncomingMessage(sendingComponent, triggeredEvent, data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
public async Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
||||||
|
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Components;
|
|||||||
using Microsoft.AspNetCore.Components.Routing;
|
using Microsoft.AspNetCore.Components.Routing;
|
||||||
|
|
||||||
using DialogOptions = AIStudio.Dialogs.DialogOptions;
|
using DialogOptions = AIStudio.Dialogs.DialogOptions;
|
||||||
|
using EnterpriseEnvironment = AIStudio.Tools.EnterpriseEnvironment;
|
||||||
|
|
||||||
namespace AIStudio.Layout;
|
namespace AIStudio.Layout;
|
||||||
|
|
||||||
@ -138,90 +139,100 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
|
|||||||
|
|
||||||
public async Task ProcessMessage<TMessage>(ComponentBase? sendingComponent, Event triggeredEvent, TMessage? data)
|
public async Task ProcessMessage<TMessage>(ComponentBase? sendingComponent, Event triggeredEvent, TMessage? data)
|
||||||
{
|
{
|
||||||
switch (triggeredEvent)
|
await this.InvokeAsync(async () =>
|
||||||
{
|
{
|
||||||
case Event.UPDATE_AVAILABLE:
|
switch (triggeredEvent)
|
||||||
if (data is UpdateResponse updateResponse)
|
{
|
||||||
{
|
case Event.UPDATE_AVAILABLE:
|
||||||
this.currentUpdateResponse = updateResponse;
|
if (data is UpdateResponse updateResponse)
|
||||||
var message = string.Format(T("An update to version {0} is available."), updateResponse.NewVersion);
|
|
||||||
this.Snackbar.Add(message, Severity.Info, config =>
|
|
||||||
{
|
{
|
||||||
config.Icon = Icons.Material.Filled.Update;
|
this.currentUpdateResponse = updateResponse;
|
||||||
config.IconSize = Size.Large;
|
var message = string.Format(T("An update to version {0} is available."), updateResponse.NewVersion);
|
||||||
config.HideTransitionDuration = 600;
|
this.Snackbar.Add(message, Severity.Info, config =>
|
||||||
config.VisibleStateDuration = 32_000;
|
|
||||||
config.OnClick = async _ =>
|
|
||||||
{
|
{
|
||||||
await this.ShowUpdateDialog();
|
config.Icon = Icons.Material.Filled.Update;
|
||||||
};
|
config.IconSize = Size.Large;
|
||||||
config.Action = T("Show details");
|
config.HideTransitionDuration = 600;
|
||||||
config.ActionVariant = Variant.Filled;
|
config.VisibleStateDuration = 32_000;
|
||||||
});
|
config.OnClick = async _ =>
|
||||||
}
|
{
|
||||||
|
await this.ShowUpdateDialog();
|
||||||
break;
|
};
|
||||||
|
config.Action = T("Show details");
|
||||||
case Event.CONFIGURATION_CHANGED:
|
config.ActionVariant = Variant.Filled;
|
||||||
if(this.SettingsManager.ConfigurationData.App.NavigationBehavior is NavBehavior.ALWAYS_EXPAND)
|
});
|
||||||
this.navBarOpen = true;
|
|
||||||
else
|
|
||||||
this.navBarOpen = false;
|
|
||||||
|
|
||||||
await this.UpdateThemeConfiguration();
|
|
||||||
this.LoadNavItems();
|
|
||||||
this.StateHasChanged();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Event.COLOR_THEME_CHANGED:
|
|
||||||
this.StateHasChanged();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Event.SHOW_SUCCESS:
|
|
||||||
if (data is DataSuccessMessage success)
|
|
||||||
success.Show(this.Snackbar);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Event.SHOW_ERROR:
|
|
||||||
if (data is DataErrorMessage error)
|
|
||||||
error.Show(this.Snackbar);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Event.SHOW_WARNING:
|
|
||||||
if (data is DataWarningMessage warning)
|
|
||||||
warning.Show(this.Snackbar);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Event.STARTUP_PLUGIN_SYSTEM:
|
|
||||||
_ = Task.Run(async () =>
|
|
||||||
{
|
|
||||||
// Set up the plugin system:
|
|
||||||
if (PluginFactory.Setup())
|
|
||||||
{
|
|
||||||
// Ensure that all internal plugins are present:
|
|
||||||
await PluginFactory.EnsureInternalPlugins();
|
|
||||||
|
|
||||||
// Load (but not start) all plugins, without waiting for them:
|
|
||||||
var pluginLoadingTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
|
||||||
await PluginFactory.LoadAll(pluginLoadingTimeout.Token);
|
|
||||||
|
|
||||||
// Set up hot reloading for plugins:
|
|
||||||
PluginFactory.SetUpHotReloading();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Event.PLUGINS_RELOADED:
|
break;
|
||||||
this.Lang = await this.SettingsManager.GetActiveLanguagePlugin();
|
|
||||||
I18N.Init(this.Lang);
|
|
||||||
this.LoadNavItems();
|
|
||||||
|
|
||||||
await this.InvokeAsync(this.StateHasChanged);
|
case Event.CONFIGURATION_CHANGED:
|
||||||
break;
|
if (this.SettingsManager.ConfigurationData.App.NavigationBehavior is NavBehavior.ALWAYS_EXPAND)
|
||||||
}
|
this.navBarOpen = true;
|
||||||
|
else
|
||||||
|
this.navBarOpen = false;
|
||||||
|
|
||||||
|
await this.UpdateThemeConfiguration();
|
||||||
|
this.LoadNavItems();
|
||||||
|
this.StateHasChanged();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Event.COLOR_THEME_CHANGED:
|
||||||
|
this.StateHasChanged();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Event.SHOW_SUCCESS:
|
||||||
|
if (data is DataSuccessMessage success)
|
||||||
|
success.Show(this.Snackbar);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Event.SHOW_ERROR:
|
||||||
|
if (data is DataErrorMessage error)
|
||||||
|
error.Show(this.Snackbar);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Event.SHOW_WARNING:
|
||||||
|
if (data is DataWarningMessage warning)
|
||||||
|
warning.Show(this.Snackbar);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Event.STARTUP_PLUGIN_SYSTEM:
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
// Set up the plugin system:
|
||||||
|
if (PluginFactory.Setup())
|
||||||
|
{
|
||||||
|
// Ensure that all internal plugins are present:
|
||||||
|
await PluginFactory.EnsureInternalPlugins();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check if there is an enterprise configuration plugin to download:
|
||||||
|
//
|
||||||
|
var enterpriseEnvironment = this.MessageBus.CheckDeferredMessages<EnterpriseEnvironment>(Event.STARTUP_ENTERPRISE_ENVIRONMENT).FirstOrDefault();
|
||||||
|
if (enterpriseEnvironment != default)
|
||||||
|
await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseEnvironment.ConfigurationId, enterpriseEnvironment.ConfigurationServerUrl);
|
||||||
|
|
||||||
|
// Load (but not start) all plugins without waiting for them:
|
||||||
|
var pluginLoadingTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||||
|
await PluginFactory.LoadAll(pluginLoadingTimeout.Token);
|
||||||
|
|
||||||
|
// Set up hot reloading for plugins:
|
||||||
|
PluginFactory.SetUpHotReloading();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Event.PLUGINS_RELOADED:
|
||||||
|
this.Lang = await this.SettingsManager.GetActiveLanguagePlugin();
|
||||||
|
I18N.Init(this.Lang);
|
||||||
|
this.LoadNavItems();
|
||||||
|
|
||||||
|
await this.InvokeAsync(this.StateHasChanged);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
||||||
|
@ -160,6 +160,7 @@ internal sealed class Program
|
|||||||
|
|
||||||
// Get the logging factory for e.g., static classes:
|
// Get the logging factory for e.g., static classes:
|
||||||
LOGGER_FACTORY = app.Services.GetRequiredService<ILoggerFactory>();
|
LOGGER_FACTORY = app.Services.GetRequiredService<ILoggerFactory>();
|
||||||
|
MessageBus.INSTANCE.Initialize(LOGGER_FACTORY.CreateLogger<MessageBus>());
|
||||||
|
|
||||||
// Get a program logger:
|
// Get a program logger:
|
||||||
var programLogger = app.Services.GetRequiredService<ILogger<Program>>();
|
var programLogger = app.Services.GetRequiredService<ILogger<Program>>();
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace AIStudio.Tools;
|
namespace AIStudio.Tools;
|
||||||
|
|
||||||
public readonly record struct EnterpriseEnvironment(string ConfigurationServerUrl, Guid ConfigurationId)
|
public readonly record struct EnterpriseEnvironment(string ConfigurationServerUrl, Guid ConfigurationId, EntityTagHeaderValue? ETag)
|
||||||
{
|
{
|
||||||
public bool IsActive => !string.IsNullOrEmpty(this.ConfigurationServerUrl) && this.ConfigurationId != Guid.Empty;
|
public bool IsActive => !string.IsNullOrEmpty(this.ConfigurationServerUrl) && this.ConfigurationId != Guid.Empty;
|
||||||
}
|
}
|
@ -9,6 +9,7 @@ public enum Event
|
|||||||
CONFIGURATION_CHANGED,
|
CONFIGURATION_CHANGED,
|
||||||
COLOR_THEME_CHANGED,
|
COLOR_THEME_CHANGED,
|
||||||
STARTUP_PLUGIN_SYSTEM,
|
STARTUP_PLUGIN_SYSTEM,
|
||||||
|
STARTUP_ENTERPRISE_ENVIRONMENT,
|
||||||
PLUGINS_RELOADED,
|
PLUGINS_RELOADED,
|
||||||
SHOW_ERROR,
|
SHOW_ERROR,
|
||||||
SHOW_WARNING,
|
SHOW_WARNING,
|
||||||
|
@ -15,10 +15,18 @@ public sealed class MessageBus
|
|||||||
private readonly ConcurrentQueue<Message> messageQueue = new();
|
private readonly ConcurrentQueue<Message> messageQueue = new();
|
||||||
private readonly SemaphoreSlim sendingSemaphore = new(1, 1);
|
private readonly SemaphoreSlim sendingSemaphore = new(1, 1);
|
||||||
|
|
||||||
|
private static ILogger<MessageBus>? LOG;
|
||||||
|
|
||||||
private MessageBus()
|
private MessageBus()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Initialize(ILogger<MessageBus> logger)
|
||||||
|
{
|
||||||
|
LOG = logger;
|
||||||
|
LOG.LogInformation("Message bus initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Define for which components and events you want to receive messages.
|
/// Define for which components and events you want to receive messages.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -61,11 +69,16 @@ public sealed class MessageBus
|
|||||||
|
|
||||||
var eventFilter = this.componentEvents[receiver];
|
var eventFilter = this.componentEvents[receiver];
|
||||||
if (eventFilter.Length == 0 || eventFilter.Contains(triggeredEvent))
|
if (eventFilter.Length == 0 || eventFilter.Contains(triggeredEvent))
|
||||||
|
|
||||||
// We don't await the task here because we don't want to block the message bus:
|
// We don't await the task here because we don't want to block the message bus:
|
||||||
_ = receiver.ProcessMessage(message.SendingComponent, message.TriggeredEvent, message.Data);
|
_ = receiver.ProcessMessage(message.SendingComponent, message.TriggeredEvent, message.Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LOG?.LogError(e, "Error while sending message.");
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
this.sendingSemaphore.Release();
|
this.sendingSemaphore.Release();
|
||||||
|
@ -1,33 +1,61 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace AIStudio.Tools.PluginSystem;
|
namespace AIStudio.Tools.PluginSystem;
|
||||||
|
|
||||||
public static partial class PluginFactory
|
public static partial class PluginFactory
|
||||||
{
|
{
|
||||||
|
public static async Task<EntityTagHeaderValue?> DetermineConfigPluginETagAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var serverUrl = configServerUrl.EndsWith('/') ? configServerUrl[..^1] : configServerUrl;
|
||||||
|
var downloadUrl = $"{serverUrl}/{configPlugId}.zip";
|
||||||
|
|
||||||
|
using var http = new HttpClient();
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Get, downloadUrl);
|
||||||
|
var response = await http.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||||
|
return response.Headers.ETag;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
LOG.LogError(e, "An error occurred while determining the ETag for the configuration plugin.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<bool> TryDownloadingConfigPluginAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default)
|
public static async Task<bool> TryDownloadingConfigPluginAsync(Guid configPlugId, string configServerUrl, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (!IS_INITIALIZED)
|
if(!IS_INITIALIZED)
|
||||||
|
{
|
||||||
|
LOG.LogWarning("Plugin factory is not yet initialized. Cannot download configuration plugin.");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
LOG.LogInformation($"Downloading configuration plugin with ID: {configPlugId} from server: {configServerUrl}");
|
var serverUrl = configServerUrl.EndsWith('/') ? configServerUrl[..^1] : configServerUrl;
|
||||||
|
var downloadUrl = $"{serverUrl}/{configPlugId}.zip";
|
||||||
|
|
||||||
|
LOG.LogInformation($"Try to download configuration plugin with ID='{configPlugId}' from server='{configServerUrl}' (GET {downloadUrl})");
|
||||||
var tempDownloadFile = Path.GetTempFileName();
|
var tempDownloadFile = Path.GetTempFileName();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var httpClient = new HttpClient();
|
using var httpClient = new HttpClient();
|
||||||
var response = await httpClient.GetAsync($"{configServerUrl}/{configPlugId}.zip", cancellationToken);
|
var response = await httpClient.GetAsync(downloadUrl, cancellationToken);
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
await using var tempFileStream = File.Create(tempDownloadFile);
|
await using(var tempFileStream = File.Create(tempDownloadFile))
|
||||||
await response.Content.CopyToAsync(tempFileStream, cancellationToken);
|
{
|
||||||
|
await response.Content.CopyToAsync(tempFileStream, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
var pluginDirectory = Path.Join(CONFIGURATION_PLUGINS_ROOT, configPlugId.ToString());
|
var configDirectory = Path.Join(CONFIGURATION_PLUGINS_ROOT, configPlugId.ToString());
|
||||||
if(Directory.Exists(pluginDirectory))
|
if(Directory.Exists(configDirectory))
|
||||||
Directory.Delete(pluginDirectory, true);
|
Directory.Delete(configDirectory, true);
|
||||||
|
|
||||||
Directory.CreateDirectory(pluginDirectory);
|
Directory.CreateDirectory(configDirectory);
|
||||||
ZipFile.ExtractToDirectory(tempDownloadFile, pluginDirectory);
|
ZipFile.ExtractToDirectory(tempDownloadFile, configDirectory);
|
||||||
|
|
||||||
LOG.LogInformation($"Configuration plugin with ID='{configPlugId}' downloaded and extracted successfully to '{pluginDirectory}'.");
|
LOG.LogInformation($"Configuration plugin with ID='{configPlugId}' downloaded and extracted successfully to '{configDirectory}'.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG.LogError($"Failed to download the enterprise configuration plugin. HTTP Status: {response.StatusCode}");
|
LOG.LogError($"Failed to download the enterprise configuration plugin. HTTP Status: {response.StatusCode}");
|
||||||
|
@ -46,6 +46,9 @@ public static partial class PluginFactory
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
LOG.LogInformation($"File changed ({changeType}): {args.FullPath}. Reloading plugins...");
|
LOG.LogInformation($"File changed ({changeType}): {args.FullPath}. Reloading plugins...");
|
||||||
|
|
||||||
|
// Wait for parallel writes to finish:
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(3));
|
||||||
await LoadAll();
|
await LoadAll();
|
||||||
await MessageBus.INSTANCE.SendMessage<bool>(null, Event.PLUGINS_RELOADED);
|
await MessageBus.INSTANCE.SendMessage<bool>(null, Event.PLUGINS_RELOADED);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ public static partial class PluginFactory
|
|||||||
if(IS_INITIALIZED)
|
if(IS_INITIALIZED)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
LOG.LogInformation("Initializing plugin factory...");
|
||||||
DATA_DIR = SettingsManager.DataDirectory!;
|
DATA_DIR = SettingsManager.DataDirectory!;
|
||||||
PLUGINS_ROOT = Path.Join(DATA_DIR, "plugins");
|
PLUGINS_ROOT = Path.Join(DATA_DIR, "plugins");
|
||||||
INTERNAL_PLUGINS_ROOT = Path.Join(PLUGINS_ROOT, ".internal");
|
INTERNAL_PLUGINS_ROOT = Path.Join(PLUGINS_ROOT, ".internal");
|
||||||
@ -37,7 +38,7 @@ public static partial class PluginFactory
|
|||||||
|
|
||||||
HOT_RELOAD_WATCHER = new(PLUGINS_ROOT);
|
HOT_RELOAD_WATCHER = new(PLUGINS_ROOT);
|
||||||
IS_INITIALIZED = true;
|
IS_INITIALIZED = true;
|
||||||
|
LOG.LogInformation("Plugin factory initialized successfully.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,11 +2,15 @@ using AIStudio.Tools.PluginSystem;
|
|||||||
|
|
||||||
namespace AIStudio.Tools.Services;
|
namespace AIStudio.Tools.Services;
|
||||||
|
|
||||||
public sealed class EnterpriseEnvironmentService(ILogger<TemporaryChatService> logger, RustService rustService) : BackgroundService
|
public sealed class EnterpriseEnvironmentService(ILogger<EnterpriseEnvironmentService> logger, RustService rustService) : BackgroundService
|
||||||
{
|
{
|
||||||
public static EnterpriseEnvironment CURRENT_ENVIRONMENT;
|
public static EnterpriseEnvironment CURRENT_ENVIRONMENT;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
private static readonly TimeSpan CHECK_INTERVAL = TimeSpan.FromMinutes(6);
|
||||||
|
#else
|
||||||
private static readonly TimeSpan CHECK_INTERVAL = TimeSpan.FromMinutes(16);
|
private static readonly TimeSpan CHECK_INTERVAL = TimeSpan.FromMinutes(16);
|
||||||
|
#endif
|
||||||
|
|
||||||
#region Overrides of BackgroundService
|
#region Overrides of BackgroundService
|
||||||
|
|
||||||
@ -14,7 +18,7 @@ public sealed class EnterpriseEnvironmentService(ILogger<TemporaryChatService> l
|
|||||||
{
|
{
|
||||||
logger.LogInformation("The enterprise environment service was initialized.");
|
logger.LogInformation("The enterprise environment service was initialized.");
|
||||||
|
|
||||||
await this.StartUpdating();
|
await this.StartUpdating(isFirstRun: true);
|
||||||
while (!stoppingToken.IsCancellationRequested)
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
await Task.Delay(CHECK_INTERVAL, stoppingToken);
|
await Task.Delay(CHECK_INTERVAL, stoppingToken);
|
||||||
@ -24,7 +28,7 @@ public sealed class EnterpriseEnvironmentService(ILogger<TemporaryChatService> l
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private async Task StartUpdating()
|
private async Task StartUpdating(bool isFirstRun = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -40,7 +44,8 @@ public sealed class EnterpriseEnvironmentService(ILogger<TemporaryChatService> l
|
|||||||
|
|
||||||
var enterpriseConfigServerUrl = await rustService.EnterpriseEnvConfigServerUrl();
|
var enterpriseConfigServerUrl = await rustService.EnterpriseEnvConfigServerUrl();
|
||||||
var enterpriseConfigId = await rustService.EnterpriseEnvConfigId();
|
var enterpriseConfigId = await rustService.EnterpriseEnvConfigId();
|
||||||
var nextEnterpriseEnvironment = new EnterpriseEnvironment(enterpriseConfigServerUrl, enterpriseConfigId);
|
var etag = await PluginFactory.DetermineConfigPluginETagAsync(enterpriseConfigId, enterpriseConfigServerUrl);
|
||||||
|
var nextEnterpriseEnvironment = new EnterpriseEnvironment(enterpriseConfigServerUrl, enterpriseConfigId, etag);
|
||||||
if (CURRENT_ENVIRONMENT != nextEnterpriseEnvironment)
|
if (CURRENT_ENVIRONMENT != nextEnterpriseEnvironment)
|
||||||
{
|
{
|
||||||
logger.LogInformation("The enterprise environment has changed. Updating the current environment.");
|
logger.LogInformation("The enterprise environment has changed. Updating the current environment.");
|
||||||
@ -62,10 +67,16 @@ public sealed class EnterpriseEnvironmentService(ILogger<TemporaryChatService> l
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
logger.LogInformation($"AI Studio runs with an enterprise configuration id ('{enterpriseConfigId}') and configuration server URL ('{enterpriseConfigServerUrl}').");
|
logger.LogInformation($"AI Studio runs with an enterprise configuration id ('{enterpriseConfigId}') and configuration server URL ('{enterpriseConfigServerUrl}').");
|
||||||
await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseConfigId, enterpriseConfigServerUrl);
|
|
||||||
|
if(isFirstRun)
|
||||||
|
MessageBus.INSTANCE.DeferMessage(null, Event.STARTUP_ENTERPRISE_ENVIRONMENT, new EnterpriseEnvironment(enterpriseConfigServerUrl, enterpriseConfigId, etag));
|
||||||
|
else
|
||||||
|
await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseConfigId, enterpriseConfigServerUrl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
logger.LogInformation("The enterprise environment has not changed. No update required.");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -1 +1,2 @@
|
|||||||
# v0.9.47, build 222 (2025-06-xx xx:xx UTC)
|
# v0.9.47, build 222 (2025-06-xx xx:xx UTC)
|
||||||
|
- We improved AI Studio for managed enterprise environments by refactoring the remote config server handling, the config plugin loading mechanism, and we improved the overall resilience.
|
@ -64,6 +64,7 @@ pub fn read_enterprise_env_config_id(_token: APIToken) -> String {
|
|||||||
// The environment variable is:
|
// The environment variable is:
|
||||||
// MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_ID
|
// MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_ID
|
||||||
//
|
//
|
||||||
|
info!("Trying to read the enterprise environment for some config ID.");
|
||||||
get_enterprise_configuration(
|
get_enterprise_configuration(
|
||||||
"config_id",
|
"config_id",
|
||||||
"MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_ID",
|
"MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_ID",
|
||||||
@ -87,6 +88,7 @@ pub fn delete_enterprise_env_config_id(_token: APIToken) -> String {
|
|||||||
// The environment variable is:
|
// The environment variable is:
|
||||||
// MINDWORK_AI_STUDIO_ENTERPRISE_DELETE_CONFIG_ID
|
// MINDWORK_AI_STUDIO_ENTERPRISE_DELETE_CONFIG_ID
|
||||||
//
|
//
|
||||||
|
info!("Trying to read the enterprise environment for some config ID, which should be deleted.");
|
||||||
get_enterprise_configuration(
|
get_enterprise_configuration(
|
||||||
"delete_config_id",
|
"delete_config_id",
|
||||||
"MINDWORK_AI_STUDIO_ENTERPRISE_DELETE_CONFIG_ID",
|
"MINDWORK_AI_STUDIO_ENTERPRISE_DELETE_CONFIG_ID",
|
||||||
@ -110,6 +112,7 @@ pub fn read_enterprise_env_config_server_url(_token: APIToken) -> String {
|
|||||||
// The environment variable is:
|
// The environment variable is:
|
||||||
// MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_SERVER_URL
|
// MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_SERVER_URL
|
||||||
//
|
//
|
||||||
|
info!("Trying to read the enterprise environment for the config server URL.");
|
||||||
get_enterprise_configuration(
|
get_enterprise_configuration(
|
||||||
"config_server_url",
|
"config_server_url",
|
||||||
"MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_SERVER_URL",
|
"MINDWORK_AI_STUDIO_ENTERPRISE_CONFIG_SERVER_URL",
|
||||||
@ -117,7 +120,6 @@ pub fn read_enterprise_env_config_server_url(_token: APIToken) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_enterprise_configuration(_reg_value: &str, env_name: &str) -> String {
|
fn get_enterprise_configuration(_reg_value: &str, env_name: &str) -> String {
|
||||||
info!("Trying to read the enterprise environment for some predefined configuration.");
|
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(target_os = "windows")] {
|
if #[cfg(target_os = "windows")] {
|
||||||
info!(r"Detected a Windows machine, trying to read the registry key 'HKEY_CURRENT_USER\Software\github\MindWork AI Studio\Enterprise IT' or environment variables.");
|
info!(r"Detected a Windows machine, trying to read the registry key 'HKEY_CURRENT_USER\Software\github\MindWork AI Studio\Enterprise IT' or environment variables.");
|
||||||
@ -133,7 +135,7 @@ fn get_enterprise_configuration(_reg_value: &str, env_name: &str) -> String {
|
|||||||
val
|
val
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
info!("Falling back to the environment variable '{}' was not successful. It appears that this is not an enterprise environment.", env_name);
|
info!("Falling back to the environment variable '{}' was not successful.", env_name);
|
||||||
"".to_string()
|
"".to_string()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -150,7 +152,7 @@ fn get_enterprise_configuration(_reg_value: &str, env_name: &str) -> String {
|
|||||||
val
|
val
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
info!("Falling back to the environment variable '{}' was not successful. It appears that this is not an enterprise environment.", env_name);
|
info!("Falling back to the environment variable '{}' was not successful.", env_name);
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,7 +164,7 @@ fn get_enterprise_configuration(_reg_value: &str, env_name: &str) -> String {
|
|||||||
match env::var(env_name) {
|
match env::var(env_name) {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
info!("The environment variable '{}' was not found. It appears that this is not an enterprise environment.", env_name);
|
info!("The environment variable '{}' was not found.", env_name);
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user