Path: redb/redb.Templates/templates/redb-chat/RedbChat.Module/AuditQueries.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Templates/templates/redb-chat/RedbChat.Module/AuditQueries.cs
----
using redb.Core;
using redb.Route.Llm.Storage.Redb.Schemas;
namespace RedbChat.Module;
///
/// Reading the audit trail back. Every stored message carries the user and the audit tags the chat route
/// stamps on it (.User(...), .Audit(...)), and they are typed properties: the filter below,
/// including the dictionary lookup, runs in the database.
///
public static class AuditQueries
{
/// The model's latest answers to one user, newest first.
public static async Task> LatestAnswersAsync(IRedbService redb, string userId, int count)
{
var messages = await redb.Query()
.Where(m => m.UserId == userId && m.Role == "assistant" && m.AuditTags!["app"] == "redbchat")
.OrderByDescending(m => m.CreatedAtUtc)
.Take(count)
.ToListAsync();
return messages
.Select(m => new AuditLine(
m.Props!.CreatedAtUtc,
m.Props.ModelId,
m.Props.InputTokens,
m.Props.OutputTokens,
string.Concat(m.Props.Content.Select(c => c.Text))))
.ToList();
}
}
public sealed record AuditLine(DateTimeOffset At, string? Model, int TokensIn, int TokensOut, string Text);