Skip to content

Commit 7e069fd

Browse files
RPC codegen (#464)
1 parent f1d8cc1 commit 7e069fd

38 files changed

+4828
-1207
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: "Codegen Check"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
paths:
9+
- 'scripts/codegen/**'
10+
- 'nodejs/src/generated/**'
11+
- 'dotnet/src/Generated/**'
12+
- 'python/copilot/generated/**'
13+
- 'go/generated_*.go'
14+
- 'go/rpc/**'
15+
- '.github/workflows/codegen-check.yml'
16+
workflow_dispatch:
17+
18+
permissions:
19+
contents: read
20+
21+
jobs:
22+
check:
23+
name: "Verify generated files are up-to-date"
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- uses: actions/setup-node@v4
29+
with:
30+
node-version: 22
31+
32+
- uses: actions/setup-go@v5
33+
with:
34+
go-version: '1.22'
35+
36+
- name: Install nodejs SDK dependencies
37+
working-directory: ./nodejs
38+
run: npm ci
39+
40+
- name: Install codegen dependencies
41+
working-directory: ./scripts/codegen
42+
run: npm ci
43+
44+
- name: Run codegen
45+
working-directory: ./scripts/codegen
46+
run: npm run generate
47+
48+
- name: Check for uncommitted changes
49+
run: |
50+
if [ -n "$(git status --porcelain)" ]; then
51+
echo "::error::Generated files are out of date. Run 'cd scripts/codegen && npm run generate' and commit the changes."
52+
git diff --stat
53+
git diff
54+
exit 1
55+
fi
56+
echo "✅ Generated files are up-to-date"

docs/guides/setup/backend-services.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ response = await session.send_and_wait({"prompt": message})
131131
<details>
132132
<summary><strong>Go</strong></summary>
133133

134+
<!-- docs-validate: skip -->
134135
```go
135136
client := copilot.NewClient(&copilot.ClientOptions{
136-
CLIUrl: "localhost:4321",
137+
CLIUrl:"localhost:4321",
137138
})
138139
client.Start(ctx)
139140
defer client.Stop()
@@ -151,6 +152,7 @@ response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: message})
151152
<details>
152153
<summary><strong>.NET</strong></summary>
153154

155+
<!-- docs-validate: skip -->
154156
```csharp
155157
var client = new CopilotClient(new CopilotClientOptions
156158
{

docs/guides/setup/bundled-cli.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ await client.stop()
105105
<details>
106106
<summary><strong>Go</strong></summary>
107107

108+
<!-- docs-validate: skip -->
108109
```go
109110
client := copilot.NewClient(&copilot.ClientOptions{
110-
CLIPath: "./vendor/copilot",
111+
CLIPath:"./vendor/copilot",
111112
})
112113
if err := client.Start(ctx); err != nil {
113114
log.Fatal(err)

docs/guides/setup/byok.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ await client.stop()
118118
<details>
119119
<summary><strong>Go</strong></summary>
120120

121+
<!-- docs-validate: skip -->
121122
```go
122123
client := copilot.NewClient(nil)
123124
client.Start(ctx)

docs/guides/setup/github-oauth.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ response = await session.send_and_wait({"prompt": "Hello!"})
170170
<details>
171171
<summary><strong>Go</strong></summary>
172172

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

199+
<!-- docs-validate: skip -->
198200
```csharp
199201
CopilotClient CreateClientForUser(string userToken) =>
200202
new CopilotClient(new CopilotClientOptions

docs/guides/setup/local-cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ await client.stop()
6868
<details>
6969
<summary><strong>Go</strong></summary>
7070

71+
<!-- docs-validate: skip -->
7172
```go
7273
client := copilot.NewClient(nil)
7374
if err := client.Start(ctx); err != nil {

dotnet/src/Client.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Text.Json;
1515
using System.Text.Json.Serialization;
1616
using System.Text.RegularExpressions;
17+
using GitHub.Copilot.SDK.Rpc;
1718

1819
namespace GitHub.Copilot.SDK;
1920

@@ -63,6 +64,19 @@ public partial class CopilotClient : IDisposable, IAsyncDisposable
6364
private readonly List<Action<SessionLifecycleEvent>> _lifecycleHandlers = new();
6465
private readonly Dictionary<string, List<Action<SessionLifecycleEvent>>> _typedLifecycleHandlers = new();
6566
private readonly object _lifecycleHandlersLock = new();
67+
private ServerRpc? _rpc;
68+
69+
/// <summary>
70+
/// Gets the typed RPC client for server-scoped methods (no session required).
71+
/// </summary>
72+
/// <remarks>
73+
/// The client must be started before accessing this property. Use <see cref="StartAsync"/> or set <see cref="CopilotClientOptions.AutoStart"/> to true.
74+
/// </remarks>
75+
/// <exception cref="ObjectDisposedException">Thrown if the client has been disposed.</exception>
76+
/// <exception cref="InvalidOperationException">Thrown if the client is not started.</exception>
77+
public ServerRpc Rpc => _disposed
78+
? throw new ObjectDisposedException(nameof(CopilotClient))
79+
: _rpc ?? throw new InvalidOperationException("Client is not started. Call StartAsync first.");
6680

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

292-
// Clear models cache
306+
// Clear RPC and models cache
307+
_rpc = null;
293308
_modelsCache = null;
294309

295310
if (ctx.NetworkStream is not null)
@@ -1040,6 +1055,9 @@ private async Task<Connection> ConnectToServerAsync(Process? cliProcess, string?
10401055
rpc.AddLocalRpcMethod("userInput.request", handler.OnUserInputRequest);
10411056
rpc.AddLocalRpcMethod("hooks.invoke", handler.OnHooksInvoke);
10421057
rpc.StartListening();
1058+
1059+
_rpc = new ServerRpc(rpc);
1060+
10431061
return new Connection(rpc, cliProcess, tcpClient, networkStream);
10441062
}
10451063

@@ -1062,6 +1080,7 @@ private static JsonSerializerOptions CreateSerializerOptions()
10621080
options.TypeInfoResolverChain.Add(TypesJsonContext.Default);
10631081
options.TypeInfoResolverChain.Add(CopilotSession.SessionJsonContext.Default);
10641082
options.TypeInfoResolverChain.Add(SessionEventsJsonContext.Default);
1083+
options.TypeInfoResolverChain.Add(SDK.Rpc.RpcJsonContext.Default);
10651084

10661085
options.MakeReadOnly();
10671086

0 commit comments

Comments
 (0)