-
Notifications
You must be signed in to change notification settings - Fork 933
Add hidden block directive to validate partial code snippets in docs #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -426,7 +426,32 @@ unsubscribeIdle(); | |
| <details> | ||
| <summary><strong>Python</strong></summary> | ||
|
|
||
| <!-- docs-validate: skip --> | ||
| <!-- docs-validate: hidden --> | ||
| ```python | ||
| from copilot import CopilotClient | ||
| from copilot.generated.session_events import SessionEvent, SessionEventType | ||
|
|
||
| client = CopilotClient() | ||
|
|
||
| session = client.create_session({"on_permission_request": lambda req, inv: {"kind": "approved"}}) | ||
|
|
||
| # Subscribe to all events | ||
| unsubscribe = session.on(lambda event: print(f"Event: {event.type}")) | ||
|
|
||
| # Filter by event type in your handler | ||
| def handle_event(event: SessionEvent) -> None: | ||
| if event.type == SessionEventType.SESSION_IDLE: | ||
| print("Session is idle") | ||
| elif event.type == SessionEventType.ASSISTANT_MESSAGE: | ||
| print(f"Message: {event.data.content}") | ||
|
|
||
| unsubscribe = session.on(handle_event) | ||
|
|
||
| # Later, to unsubscribe: | ||
| unsubscribe() | ||
| ``` | ||
| <!-- /docs-validate: hidden --> | ||
|
|
||
| ```python | ||
| # Subscribe to all events | ||
| unsubscribe = session.on(lambda event: print(f"Event: {event.type}")) | ||
|
|
@@ -449,7 +474,39 @@ unsubscribe() | |
| <details> | ||
| <summary><strong>Go</strong></summary> | ||
|
|
||
| <!-- docs-validate: skip --> | ||
| <!-- docs-validate: hidden --> | ||
| ```go | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| copilot "github.com/github/copilot-sdk/go" | ||
| ) | ||
|
|
||
| func main() { | ||
| session := &copilot.Session{} | ||
|
|
||
| // Subscribe to all events | ||
| unsubscribe := session.On(func(event copilot.SessionEvent) { | ||
| fmt.Println("Event:", event.Type) | ||
| }) | ||
|
|
||
| // Filter by event type in your handler | ||
| session.On(func(event copilot.SessionEvent) { | ||
| if event.Type == "session.idle" { | ||
| fmt.Println("Session is idle") | ||
| } else if event.Type == "assistant.message" { | ||
| fmt.Println("Message:", *event.Data.Content) | ||
| } | ||
| }) | ||
|
|
||
| // Later, to unsubscribe: | ||
| unsubscribe() | ||
| } | ||
| ``` | ||
| <!-- /docs-validate: hidden --> | ||
|
|
||
| ```go | ||
| // Subscribe to all events | ||
| unsubscribe := session.On(func(event copilot.SessionEvent) { | ||
|
|
@@ -474,7 +531,38 @@ unsubscribe() | |
| <details> | ||
| <summary><strong>.NET</strong></summary> | ||
|
|
||
| <!-- docs-validate: skip --> | ||
| <!-- docs-validate: hidden --> | ||
| ```csharp | ||
| using GitHub.Copilot.SDK; | ||
|
|
||
| public static class EventSubscriptionExample | ||
| { | ||
| public static void Example(CopilotSession session) | ||
| { | ||
| // Subscribe to all events | ||
| var unsubscribe = session.On(ev => Console.WriteLine($"Event: {ev.Type}")); | ||
|
|
||
| // Filter by event type using pattern matching | ||
| session.On(ev => | ||
| { | ||
| switch (ev) | ||
| { | ||
| case SessionIdleEvent: | ||
| Console.WriteLine("Session is idle"); | ||
| break; | ||
| case AssistantMessageEvent msg: | ||
| Console.WriteLine($"Message: {msg.Data.Content}"); | ||
| break; | ||
| } | ||
| }); | ||
|
|
||
| // Later, to unsubscribe: | ||
| unsubscribe.Dispose(); | ||
| } | ||
| } | ||
| ``` | ||
| <!-- /docs-validate: hidden --> | ||
|
|
||
| ```csharp | ||
| // Subscribe to all events | ||
| var unsubscribe = session.On(ev => Console.WriteLine($"Event: {ev.Type}")); | ||
|
|
@@ -1227,7 +1315,37 @@ session = await client.create_session({"on_permission_request": PermissionHandle | |
| <details> | ||
| <summary><strong>Go</strong></summary> | ||
|
|
||
| <!-- docs-validate: skip --> | ||
| <!-- docs-validate: hidden --> | ||
| ```go | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "log" | ||
|
|
||
| copilot "github.com/github/copilot-sdk/go" | ||
| ) | ||
|
|
||
| func main() { | ||
| ctx := context.Background() | ||
|
|
||
| client := copilot.NewClient(&copilot.ClientOptions{ | ||
| CLIUrl: "localhost:4321", | ||
| }) | ||
|
|
||
| if err := client.Start(ctx); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| defer client.Stop() | ||
|
|
||
| // Use the client normally | ||
| _, _ = client.CreateSession(ctx, &copilot.SessionConfig{ | ||
| OnPermissionRequest: copilot.PermissionHandler.ApproveAll, | ||
| }) | ||
|
Comment on lines
+1341
to
+1344
|
||
| } | ||
| ``` | ||
| <!-- /docs-validate: hidden --> | ||
|
|
||
| ```go | ||
| import copilot "github.com/github/copilot-sdk/go" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hidden “full compilable code” Python example calls
client.create_session(...)withoutawait, butCopilotClient.create_sessionis async in the SDK. To keep the hidden block accurate and actually runnable, wrap it in an asyncmain()and useawait client.start(),session = await client.create_session(...), andawait client.stop()(similar to earlier Python samples in this doc).