< Summary

Information
Class: NexusLabs.Needlr.Copilot.CopilotToolSet
Assembly: NexusLabs.Needlr.Copilot
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Copilot/CopilotToolSet.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 90
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Create(...)100%22100%
Create(...)50%22100%
Create(...)100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Copilot/CopilotToolSet.cs

#LineLine coverage
 1using Microsoft.Extensions.AI;
 2
 3namespace NexusLabs.Needlr.Copilot;
 4
 5/// <summary>
 6/// Configuration for which Copilot-backed tools to enable.
 7/// </summary>
 8public sealed class CopilotToolSetOptions
 9{
 10    /// <summary>
 11    /// Enable the Copilot <c>web_search</c> tool (calls the GitHub MCP server).
 12    /// Defaults to <c>false</c>.
 13    /// </summary>
 14    public bool EnableWebSearch { get; set; }
 15}
 16
 17/// <summary>
 18/// Factory for creating Copilot-backed <see cref="AIFunction"/> instances.
 19/// Use with Needlr's agent framework tool sets or pass directly to
 20/// <see cref="ChatOptions.Tools"/>.
 21/// </summary>
 22/// <example>
 23/// <code>
 24/// // Config-driven tool toggle:
 25/// var tools = CopilotToolSet.Create(new CopilotToolSetOptions { EnableWebSearch = true });
 26///
 27/// // With callback:
 28/// var tools = CopilotToolSet.Create(t => t.EnableWebSearch = true);
 29/// </code>
 30/// </example>
 31public static class CopilotToolSet
 32{
 33    /// <summary>
 34    /// Creates Copilot-backed <see cref="AIFunction"/> instances based on the options.
 35    /// The returned functions call the GitHub Copilot MCP server using the provided
 36    /// OAuth token provider.
 37    /// </summary>
 38    /// <param name="oauthProvider">Provides the GitHub OAuth token for MCP authentication.</param>
 39    /// <param name="toolOptions">Controls which tools are enabled.</param>
 40    /// <param name="clientOptions">Optional Copilot API configuration.</param>
 41    /// <returns>A list of enabled <see cref="AIFunction"/> instances.</returns>
 42    public static IReadOnlyList<AIFunction> Create(
 43        IGitHubOAuthTokenProvider oauthProvider,
 44        CopilotToolSetOptions toolOptions,
 45        CopilotChatClientOptions? clientOptions = null)
 46    {
 247        ArgumentNullException.ThrowIfNull(oauthProvider);
 248        ArgumentNullException.ThrowIfNull(toolOptions);
 49
 250        var functions = new List<AIFunction>();
 51
 252        if (toolOptions.EnableWebSearch)
 53        {
 154            var mcpClient = new CopilotMcpToolClient(oauthProvider, clientOptions);
 155            functions.Add(new CopilotWebSearchFunction(mcpClient));
 56        }
 57
 258        return functions;
 59    }
 60
 61    /// <summary>
 62    /// Creates Copilot-backed tools with automatic OAuth token discovery.
 63    /// </summary>
 64    /// <param name="toolOptions">Controls which tools are enabled.</param>
 65    /// <param name="clientOptions">Optional Copilot API configuration.</param>
 66    /// <returns>A list of enabled <see cref="AIFunction"/> instances.</returns>
 67    public static IReadOnlyList<AIFunction> Create(
 68        CopilotToolSetOptions toolOptions,
 69        CopilotChatClientOptions? clientOptions = null)
 70    {
 271        var options = clientOptions ?? new CopilotChatClientOptions();
 272        var oauthProvider = new GitHubOAuthTokenProvider(options);
 273        return Create(oauthProvider, toolOptions, options);
 74    }
 75
 76    /// <summary>
 77    /// Creates Copilot-backed tools with a configuration callback.
 78    /// </summary>
 79    /// <param name="configure">Callback to configure which tools to enable.</param>
 80    /// <param name="clientOptions">Optional Copilot API configuration.</param>
 81    /// <returns>A list of enabled <see cref="AIFunction"/> instances.</returns>
 82    public static IReadOnlyList<AIFunction> Create(
 83        Action<CopilotToolSetOptions> configure,
 84        CopilotChatClientOptions? clientOptions = null)
 85    {
 186        var toolOptions = new CopilotToolSetOptions();
 187        configure(toolOptions);
 188        return Create(toolOptions, clientOptions);
 89    }
 90}