Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/codegen-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Codegen Check"

on:
push:
branches:
- main
pull_request:
paths:
- 'scripts/codegen/**'
- 'nodejs/src/generated/**'
- 'dotnet/src/Generated/**'
- 'python/copilot/generated/**'
- 'go/generated_*.go'
- 'go/rpc/**'
- '.github/workflows/codegen-check.yml'
workflow_dispatch:

permissions:
contents: read

jobs:
check:
name: "Verify generated files are up-to-date"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22

- uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Install nodejs SDK dependencies
working-directory: ./nodejs
run: npm ci

- name: Install codegen dependencies
working-directory: ./scripts/codegen
run: npm ci

- name: Run codegen
working-directory: ./scripts/codegen
run: npm run generate

- name: Check for uncommitted changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "::error::Generated files are out of date. Run 'cd scripts/codegen && npm run generate' and commit the changes."
git diff --stat
git diff
exit 1
fi
echo "✅ Generated files are up-to-date"
4 changes: 3 additions & 1 deletion docs/guides/setup/backend-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ response = await session.send_and_wait({"prompt": message})
<details>
<summary><strong>Go</strong></summary>

<!-- docs-validate: skip -->
```go
client := copilot.NewClient(&copilot.ClientOptions{
CLIUrl: "localhost:4321",
CLIUrl:"localhost:4321",
})
client.Start(ctx)
defer client.Stop()
Expand All @@ -151,6 +152,7 @@ response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: message})
<details>
<summary><strong>.NET</strong></summary>

<!-- docs-validate: skip -->
```csharp
var client = new CopilotClient(new CopilotClientOptions
{
Expand Down
3 changes: 2 additions & 1 deletion docs/guides/setup/bundled-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ await client.stop()
<details>
<summary><strong>Go</strong></summary>

<!-- docs-validate: skip -->
```go
client := copilot.NewClient(&copilot.ClientOptions{
CLIPath: "./vendor/copilot",
CLIPath:"./vendor/copilot",
})
if err := client.Start(ctx); err != nil {
log.Fatal(err)
Expand Down
1 change: 1 addition & 0 deletions docs/guides/setup/byok.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ await client.stop()
<details>
<summary><strong>Go</strong></summary>

<!-- docs-validate: skip -->
```go
client := copilot.NewClient(nil)
client.Start(ctx)
Expand Down
2 changes: 2 additions & 0 deletions docs/guides/setup/github-oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ response = await session.send_and_wait({"prompt": "Hello!"})
<details>
<summary><strong>Go</strong></summary>

<!-- docs-validate: skip -->
```go
func createClientForUser(userToken string) *copilot.Client {
return copilot.NewClient(&copilot.ClientOptions{
Expand All @@ -195,6 +196,7 @@ response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Hello!"}
<details>
<summary><strong>.NET</strong></summary>

<!-- docs-validate: skip -->
```csharp
CopilotClient CreateClientForUser(string userToken) =>
new CopilotClient(new CopilotClientOptions
Expand Down
1 change: 1 addition & 0 deletions docs/guides/setup/local-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ await client.stop()
<details>
<summary><strong>Go</strong></summary>

<!-- docs-validate: skip -->
```go
client := copilot.NewClient(nil)
if err := client.Start(ctx); err != nil {
Expand Down
21 changes: 20 additions & 1 deletion dotnet/src/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using GitHub.Copilot.SDK.Rpc;

namespace GitHub.Copilot.SDK;

Expand Down Expand Up @@ -63,6 +64,19 @@ public partial class CopilotClient : IDisposable, IAsyncDisposable
private readonly List<Action<SessionLifecycleEvent>> _lifecycleHandlers = new();
private readonly Dictionary<string, List<Action<SessionLifecycleEvent>>> _typedLifecycleHandlers = new();
private readonly object _lifecycleHandlersLock = new();
private ServerRpc? _rpc;

/// <summary>
/// Gets the typed RPC client for server-scoped methods (no session required).
/// </summary>
/// <remarks>
/// The client must be started before accessing this property. Use <see cref="StartAsync"/> or set <see cref="CopilotClientOptions.AutoStart"/> to true.
/// </remarks>
/// <exception cref="ObjectDisposedException">Thrown if the client has been disposed.</exception>
/// <exception cref="InvalidOperationException">Thrown if the client is not started.</exception>
public ServerRpc Rpc => _disposed
? throw new ObjectDisposedException(nameof(CopilotClient))
: _rpc ?? throw new InvalidOperationException("Client is not started. Call StartAsync first.");

/// <summary>
/// Creates a new instance of <see cref="CopilotClient"/>.
Expand Down Expand Up @@ -289,7 +303,8 @@ private async Task CleanupConnectionAsync(List<Exception>? errors)
try { ctx.Rpc.Dispose(); }
catch (Exception ex) { errors?.Add(ex); }

// Clear models cache
// Clear RPC and models cache
_rpc = null;
_modelsCache = null;

if (ctx.NetworkStream is not null)
Expand Down Expand Up @@ -1040,6 +1055,9 @@ private async Task<Connection> ConnectToServerAsync(Process? cliProcess, string?
rpc.AddLocalRpcMethod("userInput.request", handler.OnUserInputRequest);
rpc.AddLocalRpcMethod("hooks.invoke", handler.OnHooksInvoke);
rpc.StartListening();

_rpc = new ServerRpc(rpc);

return new Connection(rpc, cliProcess, tcpClient, networkStream);
}

Expand All @@ -1062,6 +1080,7 @@ private static JsonSerializerOptions CreateSerializerOptions()
options.TypeInfoResolverChain.Add(TypesJsonContext.Default);
options.TypeInfoResolverChain.Add(CopilotSession.SessionJsonContext.Default);
options.TypeInfoResolverChain.Add(SessionEventsJsonContext.Default);
options.TypeInfoResolverChain.Add(SDK.Rpc.RpcJsonContext.Default);

options.MakeReadOnly();

Expand Down
Loading
Loading