Added a way to read what the AI received from your sources (#1100)

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
Paul KoudelkaandThorsten Sommer authored and GitHub committed 2026-10-26 10:00:01 +01:00
1 parent e0d8e18f34
commit cbc4ce5413
229 files changed
+12739 -1269

No files matched your search

@@ -0,0 +1,62 @@
using System.Reflection;
using AIStudio.Tools.Databases;
using AIStudio.Tools.Databases.ProvenanceStore;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Logging.Abstractions;
namespace AIStudio.Tests.Tools.Databases;
/// <summary>
/// A provenance store in a directory of its own, migrated the way the app migrates its own, and
/// deleted again afterward.
/// </summary>
/// <param name="directory">The directory the database lives in.</param>
/// <param name="databasePath">The path of the database file.</param>
internal sealed class TemporaryProvenanceStore(string directory, string databasePath) : IAsyncDisposable
{
public SqliteProvenanceStoreClientImplementation Client { get; } = new("SQLite", databasePath, directory, string.Empty);
/// <summary>
/// The file of the database, to check what it holds on the disk.
/// </summary>
public string DatabasePath => databasePath;
public static async Task<TemporaryProvenanceStore> CreateAsync()
{
SQLitePCL.Batteries_V2.Init();
var directory = Path.Combine(Path.GetTempPath(), $"ai-studio-provenance-store-{Guid.NewGuid():N}");
Directory.CreateDirectory(directory);
var store = new TemporaryProvenanceStore(directory, Path.Combine(directory, "provenance.sqlite3"));
await using var context = store.CreateContext();
await ProvenanceStoreSchemaMigrator.MigrateAsync(context, CancellationToken.None);
return store;
}
/// <summary>
/// Makes a provider of the database clients which hands out this store, and nothing else.
/// </summary>
public DatabaseClientProvider CreateClientProvider()
{
var databases = new DatabaseClientProvider(null!, NullLoggerFactory.Instance);
var clients = (Dictionary<DatabaseRole, DatabaseClient>)typeof(DatabaseClientProvider).GetField("clients", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(databases)!;
clients.Add(DatabaseRole.PROVENANCE_STORE, this.Client);
return databases;
}
/// <summary>
/// Opens the database directly, to check what the client does not show.
/// </summary>
public ProvenanceStoreDbContext CreateContext() => new(ProvenanceStoreDbContext.CreateOptions(databasePath));
public ValueTask DisposeAsync()
{
// The pooled connections hold the file open, which would keep it from being deleted on Windows:
SqliteConnection.ClearAllPools();
Directory.Delete(directory, true);
return ValueTask.CompletedTask;
}
}