using System.Runtime.CompilerServices; using Microsoft.Extensions.AI; namespace PiiRedaction.Core.Tests.TestSupport; public sealed class CapturingChatClient : IChatClient { public string? LastUserMessage { get; private set; } public Task GetResponseAsync( IEnumerable messages, ChatOptions? options = null, CancellationToken cancellationToken = default) { LastUserMessage = messages.LastOrDefault(message => message.Role == ChatRole.User)?.Text; var response = new ChatResponse(new ChatMessage( ChatRole.Assistant, $"Captured {LastUserMessage?.Length ?? 0} chars.")); return Task.FromResult(response); } public async IAsyncEnumerable GetStreamingResponseAsync( IEnumerable messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) { var response = await GetResponseAsync(messages, options, cancellationToken).ConfigureAwait(false); yield return new ChatResponseUpdate(ChatRole.Assistant, response.Messages.Last().Text); } public object? GetService(Type serviceType, object? serviceKey = null) => null; public void Dispose() { } }