Refractored.GitHub.Copilot.SDK.Helpers
1.2.1
dotnet add package Refractored.GitHub.Copilot.SDK.Helpers --version 1.2.1
NuGet\Install-Package Refractored.GitHub.Copilot.SDK.Helpers -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Refractored.GitHub.Copilot.SDK.Helpers" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Refractored.GitHub.Copilot.SDK.Helpers" Version="1.2.1" />
<PackageReference Include="Refractored.GitHub.Copilot.SDK.Helpers" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Refractored.GitHub.Copilot.SDK.Helpers --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Refractored.GitHub.Copilot.SDK.Helpers, 1.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Refractored.GitHub.Copilot.SDK.Helpers@1.2.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Refractored.GitHub.Copilot.SDK.Helpers&version=1.2.1
#tool nuget:?package=Refractored.GitHub.Copilot.SDK.Helpers&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Refractored.GitHub.Copilot.SDK.Helpers
Reusable helper utilities for the GitHub Copilot SDK for .NET. This library provides common functionality for CLI-based Copilot applications.
Installation
dotnet add package Refractored.GitHub.Copilot.SDK.Helpers
Features
CliChecker
Checks if the Copilot CLI is installed and the user is authenticated using the Copilot SDK.
using Refractored.GitHub.Copilot.SDK.Helpers;
// Check status with console output
var status = await CliChecker.CheckCopilotStatusAsync();
// Or check silently (no console output)
var status = await CliChecker.CheckCopilotStatusSilentAsync();
if (!CliChecker.IsReady(status))
{
Console.WriteLine("Copilot is not ready!");
return;
}
ModelSelector
Fetches available models from the Copilot SDK and allows selection.
using Refractored.GitHub.Copilot.SDK.Helpers;
// Interactive selection via console
var model = await ModelSelector.SelectModelAsync();
// Get all available models (names only)
var models = await ModelSelector.GetModelsAsync();
// Get models with full info including billing multipliers
var modelsInfo = await ModelSelector.GetModelsWithInfoAsync();
foreach (var modelInfo in modelsInfo)
{
Console.WriteLine($"{modelInfo.Id}: Multiplier = {modelInfo.Billing?.Multiplier}");
}
// Get the default (first) model
var defaultModel = await ModelSelector.GetDefaultModelAsync();
// Select by index (0-based)
var model = await ModelSelector.SelectModelByIndexAsync(2);
// Optionally pass an existing CopilotClient to reuse the connection
var client = new CopilotClient();
await client.StartAsync();
var models = await ModelSelector.GetModelsAsync(client);
ChatHelper
Helper methods for streaming chat interactions.
using GitHub.Copilot.SDK;
using Refractored.GitHub.Copilot.SDK.Helpers;
// Stream response to console with colored output
await ChatHelper.SendMessageAndStreamResponse(session, "Hello, Copilot!");
// Get complete response as string
var response = await ChatHelper.SendMessageAndGetResponseAsync(session, "What is 2+2?");
// Use callbacks for custom handling
await ChatHelper.SendMessageWithCallbacksAsync(
session,
"Explain async/await",
onDelta: text => Console.Write(text),
onComplete: () => Console.WriteLine("\n[Done]"),
onError: err => Console.WriteLine($"Error: {err}")
);
SessionManager
Manages Copilot sessions including listing, resuming, and cleanup.
using GitHub.Copilot.SDK;
using Refractored.GitHub.Copilot.SDK.Helpers;
// List all available sessions with formatted console output
var sessions = await SessionManager.ListSessionsAsync();
// Get sessions without console output
var sessions = await SessionManager.GetSessionsAsync();
// Get the most recently used session ID
var lastSessionId = await SessionManager.GetLastSessionIdAsync();
// Resume the last session
var client = new CopilotClient();
await client.StartAsync();
var session = await SessionManager.ResumeLastSessionAsync(client);
// Delete a specific session
await SessionManager.DeleteSessionAsync("session-id-123");
// Clean up old sessions (older than 7 days)
int deletedCount = await SessionManager.CleanupOldSessionsAsync(TimeSpan.FromDays(7));
// Get CLI version and protocol information
var status = await SessionManager.ShowCliStatusAsync();
Console.WriteLine($"CLI Version: {status.Version}");
// Optionally pass an existing CopilotClient to reuse the connection
var client = new CopilotClient();
await client.StartAsync();
var sessions = await SessionManager.GetSessionsAsync(client);
Prerequisites
- .NET 8.0, .NET 9.0, or .NET 10.0
- GitHub Copilot CLI installed and configured
- GitHub Copilot access on your GitHub account
Installing Copilot CLI
# macOS/Linux (Homebrew)
brew install copilot-cli
# Windows (WinGet)
winget install GitHub.Copilot
# npm (requires Node.js 22+)
npm install -g @github/copilot
# macOS/Linux (install script)
curl -fsSL https://gh.io/copilot-install | bash
Authentication
Either:
- Run
copilot, then type/loginand follow prompts - Set
GH_TOKENenvironment variable with a token that has "Copilot Requests" permission
Full Example
using GitHub.Copilot.SDK;
using Refractored.GitHub.Copilot.SDK.Helpers;
// Check prerequisites
var status = await CliChecker.CheckCopilotStatusAsync();
if (!CliChecker.IsReady(status))
return;
// Select a model
var model = await ModelSelector.SelectModelAsync();
if (model == null)
return;
// Start client and create session
using var client = new CopilotClient();
await client.StartAsync();
using var session = await client.CreateSessionAsync(new SessionConfig
{
Model = model,
Streaming = true
});
// Chat!
await ChatHelper.SendMessageAndStreamResponse(session, "Hello, Copilot!");
License
MIT License - see LICENSE file.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- GitHub.Copilot.SDK (>= 0.1.18)
-
net8.0
- GitHub.Copilot.SDK (>= 0.1.18)
-
net9.0
- GitHub.Copilot.SDK (>= 0.1.18)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.