@@ -426,7 +426,32 @@ unsubscribeIdle();
426426<details >
427427<summary ><strong >Python</strong ></summary >
428428
429- <!-- docs-validate: skip -->
429+ <!-- docs-validate: hidden -->
430+ ``` python
431+ from copilot import CopilotClient
432+ from copilot.generated.session_events import SessionEvent, SessionEventType
433+
434+ client = CopilotClient()
435+
436+ session = client.create_session({" on_permission_request" : lambda req , inv : {" kind" : " approved" }})
437+
438+ # Subscribe to all events
439+ unsubscribe = session.on(lambda event : print (f " Event: { event.type} " ))
440+
441+ # Filter by event type in your handler
442+ def handle_event (event : SessionEvent) -> None :
443+ if event.type == SessionEventType.SESSION_IDLE :
444+ print (" Session is idle" )
445+ elif event.type == SessionEventType.ASSISTANT_MESSAGE :
446+ print (f " Message: { event.data.content} " )
447+
448+ unsubscribe = session.on(handle_event)
449+
450+ # Later, to unsubscribe:
451+ unsubscribe()
452+ ```
453+ <!-- /docs-validate: hidden -->
454+
430455``` python
431456# Subscribe to all events
432457unsubscribe = session.on(lambda event : print (f " Event: { event.type} " ))
@@ -449,7 +474,39 @@ unsubscribe()
449474<details >
450475<summary ><strong >Go</strong ></summary >
451476
452- <!-- docs-validate: skip -->
477+ <!-- docs-validate: hidden -->
478+ ``` go
479+ package main
480+
481+ import (
482+ " fmt"
483+
484+ copilot " github.com/github/copilot-sdk/go"
485+ )
486+
487+ func main () {
488+ session := &copilot.Session {}
489+
490+ // Subscribe to all events
491+ unsubscribe := session.On (func (event copilot.SessionEvent ) {
492+ fmt.Println (" Event:" , event.Type )
493+ })
494+
495+ // Filter by event type in your handler
496+ session.On (func (event copilot.SessionEvent ) {
497+ if event.Type == " session.idle" {
498+ fmt.Println (" Session is idle" )
499+ } else if event.Type == " assistant.message" {
500+ fmt.Println (" Message:" , *event.Data .Content )
501+ }
502+ })
503+
504+ // Later, to unsubscribe:
505+ unsubscribe ()
506+ }
507+ ```
508+ <!-- /docs-validate: hidden -->
509+
453510``` go
454511// Subscribe to all events
455512unsubscribe := session.On (func (event copilot.SessionEvent ) {
@@ -474,7 +531,38 @@ unsubscribe()
474531<details >
475532<summary ><strong >.NET</strong ></summary >
476533
477- <!-- docs-validate: skip -->
534+ <!-- docs-validate: hidden -->
535+ ``` csharp
536+ using GitHub .Copilot .SDK ;
537+
538+ public static class EventSubscriptionExample
539+ {
540+ public static void Example (CopilotSession session )
541+ {
542+ // Subscribe to all events
543+ var unsubscribe = session .On (ev => Console .WriteLine ($" Event: {ev .Type }" ));
544+
545+ // Filter by event type using pattern matching
546+ session .On (ev =>
547+ {
548+ switch (ev )
549+ {
550+ case SessionIdleEvent :
551+ Console .WriteLine (" Session is idle" );
552+ break ;
553+ case AssistantMessageEvent msg :
554+ Console .WriteLine ($" Message: {msg .Data .Content }" );
555+ break ;
556+ }
557+ });
558+
559+ // Later, to unsubscribe:
560+ unsubscribe .Dispose ();
561+ }
562+ }
563+ ```
564+ <!-- /docs-validate: hidden -->
565+
478566``` csharp
479567// Subscribe to all events
480568var unsubscribe = session .On (ev => Console .WriteLine ($" Event: {ev .Type }" ));
@@ -1227,7 +1315,37 @@ session = await client.create_session({"on_permission_request": PermissionHandle
12271315<details >
12281316<summary ><strong >Go</strong ></summary >
12291317
1230- <!-- docs-validate: skip -->
1318+ <!-- docs-validate: hidden -->
1319+ ``` go
1320+ package main
1321+
1322+ import (
1323+ " context"
1324+ " log"
1325+
1326+ copilot " github.com/github/copilot-sdk/go"
1327+ )
1328+
1329+ func main () {
1330+ ctx := context.Background ()
1331+
1332+ client := copilot.NewClient (&copilot.ClientOptions {
1333+ CLIUrl: " localhost:4321" ,
1334+ })
1335+
1336+ if err := client.Start (ctx); err != nil {
1337+ log.Fatal (err)
1338+ }
1339+ defer client.Stop ()
1340+
1341+ // Use the client normally
1342+ _, _ = client.CreateSession (ctx, &copilot.SessionConfig {
1343+ OnPermissionRequest: copilot.PermissionHandler .ApproveAll ,
1344+ })
1345+ }
1346+ ```
1347+ <!-- /docs-validate: hidden -->
1348+
12311349``` go
12321350import copilot " github.com/github/copilot-sdk/go"
12331351
0 commit comments