| | | 1 | | namespace NexusLabs.Needlr.AgentFramework.Providers; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// A provider in a priority-ordered fallback chain. Providers are tried in order of |
| | | 5 | | /// ascending <see cref="Priority"/> until one succeeds or all fail. |
| | | 6 | | /// </summary> |
| | | 7 | | /// <typeparam name="TQuery">The query/request type.</typeparam> |
| | | 8 | | /// <typeparam name="TResult">The result type.</typeparam> |
| | | 9 | | public interface ITieredProvider<in TQuery, TResult> |
| | | 10 | | { |
| | | 11 | | /// <summary>Gets the provider's display name (used in diagnostics and logging).</summary> |
| | | 12 | | string Name { get; } |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets the priority for ordering. Lower values = higher priority (tried first). |
| | | 16 | | /// </summary> |
| | | 17 | | int Priority { get; } |
| | | 18 | | |
| | | 19 | | /// <summary>Gets whether this provider is enabled and should participate in the chain.</summary> |
| | | 20 | | bool IsEnabled { get; } |
| | | 21 | | |
| | | 22 | | /// <summary>Executes the query against this provider.</summary> |
| | | 23 | | /// <exception cref="ProviderUnavailableException"> |
| | | 24 | | /// The provider is temporarily unavailable. The selector will try the next provider. |
| | | 25 | | /// </exception> |
| | | 26 | | Task<TResult> ExecuteAsync(TQuery query, CancellationToken cancellationToken); |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Thrown when a provider is temporarily unavailable. The tiered selector catches this |
| | | 31 | | /// and falls through to the next provider in the chain. |
| | | 32 | | /// </summary> |
| | | 33 | | public class ProviderUnavailableException : Exception |
| | | 34 | | { |
| | | 35 | | /// <summary>Gets the name of the provider that was unavailable.</summary> |
| | 0 | 36 | | public string ProviderName { get; } |
| | | 37 | | |
| | | 38 | | /// <param name="providerName">The provider that was unavailable.</param> |
| | | 39 | | /// <param name="message">A description of why the provider is unavailable.</param> |
| | | 40 | | /// <param name="innerException">The original exception, if any.</param> |
| | | 41 | | public ProviderUnavailableException(string providerName, string message, Exception? innerException = null) |
| | 4 | 42 | | : base(message, innerException) |
| | | 43 | | { |
| | 4 | 44 | | ProviderName = providerName; |
| | 4 | 45 | | } |
| | | 46 | | } |