SRO.AI.Copilot 1.0.1
IFI.AI.Copilot
A simplified, multi-platform .NET API for interfacing with the GitHub Copilot CLI, providing transactional prompt-response interactions with Copilot.
Overview
IFI.AI.Copilot is a streamlined alternative to the GitHub.Copilot.SDK that offers:
- Simplified API: Easy-to-use interface with minimal complexity
- Multi-Platform Support: Compatible with both .NET Framework (4.7.2, 4.8) and .NET Core (.NET 8.0)
- Straightforward Integration: Just three steps - construct, initialize, and send
Key Features
- Simple API Surface: No complex configurations or extensive setup required
- Cross-Platform Compatibility: Works across multiple .NET versions
- Conversation History: Automatically maintains context across messages
- Event-Driven Logging: Subscribe to diagnostic and logging events
- Async/Await Support: Full support for asynchronous operations
- Thread-Safe: Built with thread-safety in mind for multi-threaded applications
Prerequisites
- GitHub Copilot CLI installed and accessible in your system PATH
- Valid GitHub Copilot subscription
- .NET Framework 4.7.2/4.8 or .NET 8.0+
Installation
Install via NuGet Package Manager:
dotnet add package IFI.AI.Copilot
Or via Package Manager Console:
Install-Package IFI.AI.Copilot
Quick Start
Basic Usage
using IFI.AI.Copilot;
// Create a new client
var copilotClient = new GitHubCopilotClient();
// Initialize the connection
copilotClient.Initialize();
// Send a message and get a response
string response = copilotClient.Send("What is the capital of France?");
Console.WriteLine(response);
// Don't forget to dispose when done
copilotClient.Dispose();
Async Usage
using IFI.AI.Copilot;
var copilotClient = new GitHubCopilotClient();
copilotClient.Initialize();
// Send messages asynchronously
string response = await copilotClient.SendAsync("Explain async/await in C#");
Console.WriteLine(response);
copilotClient.Dispose();
Using Statement (Recommended)
using (var copilotClient = new GitHubCopilotClient())
{
copilotClient.Initialize();
var response = copilotClient.Send("Write a hello world function in C#");
Console.WriteLine(response);
}
API Reference
GitHubCopilotClient Class
The main class for interacting with the GitHub Copilot CLI.
Constructor
public GitHubCopilotClient()
Creates a new instance of the GitHub Copilot client.
Methods
Initialize
public void Initialize(int timeoutMilliseconds = 120000)
Initializes the GitHub Copilot Connector, including starting the GitHub Copilot CLI process and setting up the JSON-RPC communication channel.
Parameters:
timeoutMilliseconds(optional): Timeout for operations in milliseconds. Default is 120000 (2 minutes).
Send
public string Send(string message)
Sends a message to the GitHub Copilot CLI synchronously and returns the response.
Parameters:
message: The message to send to GitHub Copilot.
Returns: The response from GitHub Copilot.
Throws:
ArgumentException: If the message is null or empty.InvalidOperationException: If the connection is not established.CopilotException: If an error occurs while communicating with Copilot.
SendAsync
public async Task<string> SendAsync(string message)
Sends a message to the GitHub Copilot CLI asynchronously and returns the response.
Parameters:
message: The message to send to GitHub Copilot.
Returns: A task containing the response from GitHub Copilot.
Throws:
ArgumentException: If the message is null or empty.InvalidOperationException: If the connection is not established.TimeoutException: If the operation times out.CopilotException: If an error occurs while communicating with Copilot.
Dispose
public void Dispose()
Releases all resources used by the GitHubCopilotClient. Always call this when finished with the client or use a using statement.
Properties
TimeoutMilliseconds
public int TimeoutMilliseconds { get; set; }
Gets or sets the timeout in milliseconds for communication operations. Default is 120000 (2 minutes).
IsInitialized
public bool IsInitialized { get; }
Gets a value indicating whether the session has been initialized.
IsConnected
public bool IsConnected { get; }
Gets a value indicating whether the JSON-RPC connection is active and ready for communication.
SessionId
public string SessionId { get; }
Gets the current session ID for the GitHub Copilot CLI conversation.
ConversationHistory
public List<ChatMessage> ConversationHistory { get; }
Gets the conversation history, which maintains context across multiple messages.
CopilotProcess
public Process CopilotProcess { get; }
Gets the GitHub Copilot CLI process instance.
Events
MessageSent
public event EventHandler<MessageSentEventArgs> MessageSent;
Raised when a message is sent from the GitHub Copilot Connector, such as log messages, errors, or diagnostic information.
Example:
copilotClient.MessageSent += (sender, args) =>
{
switch (args.LogLevel)
{
case MessageLogLevel.Info:
Console.WriteLine($"INFO: {args.Message}");
break;
case MessageLogLevel.Warning:
Console.WriteLine($"WARNING: {args.Message}");
break;
case MessageLogLevel.Error:
Console.WriteLine($"ERROR: {args.Message}");
break;
}
};
Supporting Classes
ChatMessage
Represents a message in the conversation history.
public class ChatMessage
{
public string Role { get; set; } // "user", "assistant", or "system"
public string Content { get; set; } // Message content
public DateTime Timestamp { get; set; } // When the message was sent
}
MessageSentEventArgs
Event arguments for the MessageSent event.
public class MessageSentEventArgs : EventArgs
{
public string Message { get; set; }
public MessageLogLevel LogLevel { get; set; }
}
MessageLogLevel Enum
Log level for diagnostic messages.
public enum MessageLogLevel
{
Verbose = 0, // Debug-level messages
Info = 1, // Informational messages
Warning = 2, // Warning messages
Error = 3 // Error messages
}
Exceptions
CopilotException
Custom exception thrown when errors occur during Copilot communication.
public class CopilotException : Exception
{
public CopilotException(string message);
public CopilotException(string message, Exception innerException);
}
Advanced Usage
With Event Logging
using (var copilotClient = new GitHubCopilotClient())
{
// Subscribe to logging events
copilotClient.MessageSent += (sender, args) =>
{
Console.WriteLine($"[{args.LogLevel}] {args.Message}");
};
copilotClient.Initialize();
string response = copilotClient.Send("Explain dependency injection");
Console.WriteLine(response);
}
Custom Timeout
using (var copilotClient = new GitHubCopilotClient())
{
// Set a custom timeout of 5 minutes
copilotClient.Initialize(timeoutMilliseconds: 300000);
string response = copilotClient.Send("Generate a complex algorithm");
Console.WriteLine(response);
}
Multiple Conversations
using (var copilotClient = new GitHubCopilotClient())
{
copilotClient.Initialize();
// First message
var response1 = copilotClient.Send("What is C#?");
Console.WriteLine(response1);
// Follow-up message (maintains context)
var response2 = copilotClient.Send("Can you give me an example?");
Console.WriteLine(response2);
// Check conversation history
Console.WriteLine($"Total messages: {copilotClient.ConversationHistory.Count}");
}
Error Handling
using (var copilotClient = new GitHubCopilotClient())
{
try
{
copilotClient.Initialize();
string response = await copilotClient.SendAsync("Your prompt here");
Console.WriteLine(response);
}
catch (CopilotException ex)
{
Console.WriteLine($"Copilot error: {ex.Message}");
if (ex.InnerException != null)
{
Console.WriteLine($"Inner exception: {ex.InnerException.Message}");
}
}
catch (TimeoutException ex)
{
Console.WriteLine($"Operation timed out: {ex.Message}");
}
catch (ArgumentException ex)
{
Console.WriteLine($"Invalid argument: {ex.Message}");
}
}
Best Practices
- Always Dispose: Use
usingstatements or explicitly callDispose()when finished - Handle Exceptions: Wrap calls in try-catch blocks to handle potential errors gracefully
- Set Appropriate Timeouts: Adjust the timeout based on your expected response times
- Monitor Events: Subscribe to the
MessageSentevent for debugging and diagnostics - Check Connection: Use
IsConnectedandIsInitializedproperties to verify state - Maintain Context: The API automatically maintains conversation history for contextual responses
Troubleshooting
GitHub Copilot CLI Not Found
Ensure that the GitHub Copilot CLI is installed and accessible in your system PATH. You can verify by running:
copilot --version
Connection Timeout
If you're experiencing timeouts, try increasing the timeout value:
copilotClient.Initialize(timeoutMilliseconds: 300000); // 5 minutes
Invalid Operation Exception
Ensure you call Initialize() before sending messages:
var client = new GitHubCopilotClient();
client.Initialize(); // Must call before Send()
var response = client.Send("Your message");
Dependencies
This package uses the following key dependencies:
- StreamJsonRpc - For JSON-RPC communication
- Newtonsoft.Json - For JSON serialization
- MessagePack - For efficient binary serialization
- Microsoft.VisualStudio.Threading - For async/await utilities
License
Copyright © 2026 Indiana Farmers Mutual Insurance Group
Support
For issues, questions, or contributions, please contact the IFI.AI development team.
Version History
1.0.0
- Initial release
- Multi-platform support (.NET Framework 4.7.2/4.8 and .NET 8.0)
- Simple three-step API (construct, initialize, send)
- Conversation history management
- Event-driven logging
- Full async/await support
No packages depend on SRO.AI.Copilot.
.NET Framework 4.7.2
- MessagePack (>= 3.1.4)
- MessagePack.Annotations (>= 3.1.4)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.3)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.NET.StringTools (>= 18.3.3)
- Microsoft.NETCore.Platforms (>= 7.0.4)
- Microsoft.VisualStudio.Threading (>= 17.13.2)
- Microsoft.VisualStudio.Threading.Only (>= 17.14.15)
- Microsoft.VisualStudio.Validation (>= 17.13.22)
- Microsoft.Win32.Registry (>= 5.0.0)
- Nerdbank.MessagePack (>= 1.0.43)
- Nerdbank.Streams (>= 2.13.16)
- Newtonsoft.Json (>= 13.0.1)
- PolyType (>= 1.0.0)
- StreamJsonRpc (>= 2.21.10)
- System.Buffers (>= 4.6.1)
- System.Collections.Immutable (>= 10.0.3)
- System.Diagnostics.DiagnosticSource (>= 10.0.3)
- System.IO.Pipelines (>= 10.0.3)
- System.Memory (>= 4.6.3)
- System.Numerics.Vectors (>= 4.6.1)
- System.Reflection.Emit (>= 4.7.0)
- System.Reflection.Emit.Lightweight (>= 4.7.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
- System.Security.AccessControl (>= 6.0.1)
- System.Security.Principal.Windows (>= 5.0.0)
- System.Text.Encodings.Web (>= 10.0.3)
- System.Text.Json (>= 10.0.3)
- System.Threading.Tasks.Dataflow (>= 10.0.3)
- System.Threading.Tasks.Extensions (>= 4.6.3)
.NET Framework 4.8
- MessagePack (>= 3.1.4)
- MessagePack.Annotations (>= 3.1.4)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.3)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.NET.StringTools (>= 18.3.3)
- Microsoft.NETCore.Platforms (>= 7.0.4)
- Microsoft.VisualStudio.Threading (>= 17.13.2)
- Microsoft.VisualStudio.Threading.Only (>= 17.14.15)
- Microsoft.VisualStudio.Validation (>= 17.13.22)
- Microsoft.Win32.Registry (>= 5.0.0)
- Nerdbank.MessagePack (>= 1.0.43)
- Nerdbank.Streams (>= 2.13.16)
- Newtonsoft.Json (>= 13.0.1)
- PolyType (>= 1.0.0)
- StreamJsonRpc (>= 2.21.10)
- System.Buffers (>= 4.6.1)
- System.Collections.Immutable (>= 10.0.3)
- System.Diagnostics.DiagnosticSource (>= 10.0.3)
- System.IO.Pipelines (>= 10.0.3)
- System.Memory (>= 4.6.3)
- System.Numerics.Vectors (>= 4.6.1)
- System.Reflection.Emit (>= 4.7.0)
- System.Reflection.Emit.Lightweight (>= 4.7.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
- System.Security.AccessControl (>= 6.0.1)
- System.Security.Principal.Windows (>= 5.0.0)
- System.Text.Encodings.Web (>= 10.0.3)
- System.Text.Json (>= 10.0.3)
- System.Threading.Tasks.Dataflow (>= 10.0.3)
- System.Threading.Tasks.Extensions (>= 4.6.3)
.NET 8.0
- MessagePack (>= 3.1.4)
- MessagePack.Annotations (>= 3.1.4)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.3)
- Microsoft.Bcl.HashCode (>= 6.0.0)
- Microsoft.NET.StringTools (>= 18.3.3)
- Microsoft.NETCore.Platforms (>= 7.0.4)
- Microsoft.VisualStudio.Threading (>= 17.13.2)
- Microsoft.VisualStudio.Threading.Only (>= 17.14.15)
- Microsoft.VisualStudio.Validation (>= 17.13.22)
- Microsoft.Win32.Registry (>= 5.0.0)
- Nerdbank.MessagePack (>= 1.0.43)
- Nerdbank.Streams (>= 2.13.16)
- Newtonsoft.Json (>= 13.0.1)
- PolyType (>= 1.0.0)
- StreamJsonRpc (>= 2.21.10)
- System.Buffers (>= 4.6.1)
- System.Collections.Immutable (>= 10.0.3)
- System.Diagnostics.DiagnosticSource (>= 10.0.3)
- System.IO.Pipelines (>= 10.0.3)
- System.Memory (>= 4.6.3)
- System.Numerics.Vectors (>= 4.6.1)
- System.Reflection.Emit (>= 4.7.0)
- System.Reflection.Emit.Lightweight (>= 4.7.0)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
- System.Security.AccessControl (>= 6.0.1)
- System.Security.Principal.Windows (>= 5.0.0)
- System.Text.Encodings.Web (>= 10.0.3)
- System.Text.Json (>= 10.0.3)
- System.Threading.Tasks.Dataflow (>= 10.0.3)
- System.Threading.Tasks.Extensions (>= 4.6.3)
| Version | Downloads | Last updated |
|---|---|---|
| 1.0.1 | 8 | 09/03/2026 |