| | | 1 | | namespace NexusLabs.Needlr.AgentFramework.Diagnostics; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// DI-registered singleton that holds the <see cref="IToolCallCollector"/> instance. |
| | | 5 | | /// The diagnostics middleware sets the real collector during factory construction; consumers |
| | | 6 | | /// resolve this to access it. Unlike a static holder, each DI container has its own instance, |
| | | 7 | | /// making it testable and thread-safe across containers. |
| | | 8 | | /// </summary> |
| | | 9 | | [DoNotAutoRegister] |
| | | 10 | | public sealed class ToolCallCollectorHolder : IToolCallCollector |
| | | 11 | | { |
| | 89 | 12 | | private IToolCallCollector _inner = NullToolCallCollector.Instance; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets whether a real (non-null) collector has been installed via |
| | | 16 | | /// <see cref="SetCollector"/>. When <see langword="true"/>, |
| | | 17 | | /// <c>UsingDiagnostics()</c> has already wired a diagnostics middleware |
| | | 18 | | /// onto the chat client pipeline and external consumers should not install |
| | | 19 | | /// a duplicate. |
| | | 20 | | /// </summary> |
| | 0 | 21 | | internal bool HasRealCollector => _inner is not NullToolCallCollector; |
| | | 22 | | |
| | | 23 | | /// <summary>Sets the real collector. Called by <c>UsingDiagnostics()</c> during factory construction.</summary> |
| | | 24 | | internal void SetCollector(IToolCallCollector collector) |
| | | 25 | | { |
| | 35 | 26 | | ArgumentNullException.ThrowIfNull(collector); |
| | 35 | 27 | | _inner = collector; |
| | 35 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | public IReadOnlyList<ToolCallDiagnostics> DrainToolCalls() => |
| | 21 | 32 | | _inner.DrainToolCalls(); |
| | | 33 | | } |