| | | 1 | | namespace NexusLabs.Needlr.SemanticKernel.PluginScanners; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Source-generation-friendly SemanticKernel plugin scanner that uses compile-time generated plugin type lists. |
| | | 5 | | /// </summary> |
| | | 6 | | /// <remarks> |
| | | 7 | | /// When using source generation, the generator emits a |
| | | 8 | | /// <c>NexusLabs.Needlr.Generated.SemanticKernelPlugins</c> class containing: |
| | | 9 | | /// - <c>StaticPluginTypes</c>: Types with static [KernelFunction] methods |
| | | 10 | | /// - <c>InstancePluginTypes</c>: Types with instance [KernelFunction] methods |
| | | 11 | | /// - <c>AllPluginTypes</c>: Combined list of all plugin types |
| | | 12 | | /// |
| | | 13 | | /// This scanner provides a reflection-free way to access these generated lists. |
| | | 14 | | /// For AOT/trimmed applications, use this scanner instead of |
| | | 15 | | /// <see cref="AssemblySemanticKernelPluginScanner"/> or |
| | | 16 | | /// <see cref="ServiceProviderSemanticKernelPluginScanner"/> which use reflection. |
| | | 17 | | /// |
| | | 18 | | /// Usage: |
| | | 19 | | /// <code> |
| | | 20 | | /// // The generated types are available in NexusLabs.Needlr.Generated namespace |
| | | 21 | | /// var pluginTypes = NexusLabs.Needlr.Generated.SemanticKernelPlugins.AllPluginTypes; |
| | | 22 | | /// |
| | | 23 | | /// // Or use this scanner wrapper |
| | | 24 | | /// var scanner = new GeneratedSemanticKernelPluginScanner(); |
| | | 25 | | /// var types = scanner.ScanForPluginTypes(); |
| | | 26 | | /// </code> |
| | | 27 | | /// </remarks> |
| | | 28 | | public sealed class GeneratedSemanticKernelPluginScanner : ISemanticKernelPluginScanner |
| | | 29 | | { |
| | | 30 | | private readonly IReadOnlyList<Type> _pluginTypes; |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Creates a new instance using the specified plugin types. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <param name="pluginTypes">The pre-discovered plugin types (typically from generated code).</param> |
| | 5 | 36 | | public GeneratedSemanticKernelPluginScanner(IReadOnlyList<Type> pluginTypes) |
| | | 37 | | { |
| | 5 | 38 | | ArgumentNullException.ThrowIfNull(pluginTypes); |
| | 4 | 39 | | _pluginTypes = pluginTypes; |
| | 4 | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | 4 | 43 | | public IReadOnlyList<Type> ScanForPluginTypes() => _pluginTypes; |
| | | 44 | | } |