Files
awesome-copilot/cookbook/copilot-sdk/dotnet/recipe/error-handling.cs
Jon Galloway e2c763df88 Update .NET Copilot SDK recipes for explicit permission (fix for SDK v0.1.28) (#1033)
* Update .NET Copilot SDK recipes for explicit permission handling (fix breaking change in SDK v0.1.28)

* Update .NET Copilot SDK recipes for explicit permission handling
2026-03-17 12:49:03 +11:00

40 lines
817 B
C#

#:package GitHub.Copilot.SDK@*
#:property PublishAot=false
using GitHub.Copilot.SDK;
var client = new CopilotClient();
try
{
await client.StartAsync();
var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "gpt-5",
OnPermissionRequest = PermissionHandler.ApproveAll
});
var done = new TaskCompletionSource<string>();
session.On(evt =>
{
if (evt is AssistantMessageEvent msg)
{
done.SetResult(msg.Data.Content);
}
});
await session.SendAsync(new MessageOptions { Prompt = "Hello!" });
var response = await done.Task;
Console.WriteLine(response);
await session.DisposeAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
finally
{
await client.StopAsync();
}