Added a preview of the document analysis assistant (#561)
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions

Co-authored-by: Peer Schütt <20603780+peerschuett@users.noreply.github.com>
This commit is contained in:
Thorsten SommerandPeer Schütt authored and GitHub committed 2025-11-24 12:37:18 +01:00
1 parent 8b0ee49ba9
commit 009bb33d83
42 files changed
+1947 -101

No files matched your search

@@ -0,0 +1,77 @@
using System.Text.Json;
using AIStudio.Tools.Rust;
namespace AIStudio.Tools.Services;
public partial class RustService
{
/// <summary>
/// Consume the Tauri event stream and forward relevant events to the message bus.
/// </summary>
/// <param name="stopToken">Cancellation token to stop the stream.</param>
private async Task StartStreamTauriEvents(CancellationToken stopToken)
{
// Outer try-catch to handle cancellation:
try
{
while (!stopToken.IsCancellationRequested)
{
// Inner try-catch to handle streaming issues:
try
{
// Open the event stream:
await using var stream = await this.http.GetStreamAsync("/events", stopToken);
// Read events line by line:
using var reader = new StreamReader(stream);
// Read until the end of the stream or cancellation:
while(!reader.EndOfStream && !stopToken.IsCancellationRequested)
{
// Read the next line of JSON from the stream:
var line = await reader.ReadLineAsync(stopToken);
// Skip empty lines:
if (string.IsNullOrWhiteSpace(line))
continue;
// Deserialize the Tauri event:
var tauriEvent = JsonSerializer.Deserialize<TauriEvent>(line, this.jsonRustSerializerOptions);
// Forward relevant events to the message bus:
if (tauriEvent != default && tauriEvent.EventType
is not TauriEventType.NONE
and not TauriEventType.UNKNOWN
and not TauriEventType.PING)
{
this.logger!.LogDebug("Received Tauri event {EventType} with {NumPayloadItems} payload items.", tauriEvent.EventType, tauriEvent.Payload.Count);
await MessageBus.INSTANCE.SendMessage(null, Event.TAURI_EVENT_RECEIVED, tauriEvent);
}
}
}
// The cancellation token was triggered, exit the loop:
catch (OperationCanceledException)
{
break;
}
// Some other error occurred, log it and retry after a delay:
catch (Exception e)
{
this.logger!.LogError("Error while streaming Tauri events: {Message}", e.Message);
await Task.Delay(TimeSpan.FromSeconds(3), stopToken);
}
}
}
// The cancellation token was triggered, exit the method:
catch (OperationCanceledException)
{
}
this.logger!.LogWarning("Stopped streaming Tauri events.");
}
}
@@ -1,6 +1,10 @@
using System.Security.Cryptography;
using System.Text.Json;
using AIStudio.Settings;
using Version = System.Version;
// ReSharper disable NotAccessedPositionalProperty.Local
namespace AIStudio.Tools.Services;
@@ -8,13 +12,14 @@ namespace AIStudio.Tools.Services;
/// <summary>
/// Calling Rust functions.
/// </summary>
public sealed partial class RustService : IDisposable
public sealed partial class RustService : BackgroundService
{
private readonly HttpClient http;
private readonly JsonSerializerOptions jsonRustSerializerOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
Converters = { new TolerantEnumConverter() },
};
private ILogger<RustService>? logger;
@@ -59,11 +64,24 @@ public sealed partial class RustService : IDisposable
this.encryptor = encryptionService;
}
#region IDisposable
#region Overrides of BackgroundService
public void Dispose()
/// <summary>
/// The main execution loop of the Rust service as a background thread.
/// </summary>
/// <param name="stopToken">The cancellation token to stop the service.</param>
protected override async Task ExecuteAsync(CancellationToken stopToken)
{
this.logger?.LogInformation("The Rust service was initialized.");
// Start consuming Tauri events:
await this.StartStreamTauriEvents(stopToken);
}
public override void Dispose()
{
this.http.Dispose();
base.Dispose();
}
#endregion
@@ -24,24 +24,24 @@ public sealed class TemporaryChatService(ILogger<TemporaryChatService> logger, S
return;
}
await this.StartMaintenance();
this.StartMaintenance();
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(CHECK_INTERVAL, stoppingToken);
await this.StartMaintenance();
this.StartMaintenance();
}
}
#endregion
private Task StartMaintenance()
private void StartMaintenance()
{
logger.LogInformation("Starting maintenance of temporary chat storage.");
var temporaryDirectories = Path.Join(SettingsManager.DataDirectory, "tempChats");
if(!Directory.Exists(temporaryDirectories))
{
logger.LogWarning("Temporary chat storage directory does not exist. End maintenance.");
return Task.CompletedTask;
return;
}
foreach (var tempChatDirPath in Directory.EnumerateDirectories(temporaryDirectories))
@@ -71,7 +71,6 @@ public sealed class TemporaryChatService(ILogger<TemporaryChatService> logger, S
}
logger.LogInformation("Finished maintenance of temporary chat storage.");
return Task.CompletedTask;
}
public static void Initialize()