@@ -75,13 +75,12 @@ func main() {
7575 }
7676 defer client.Stop()
7777
78- streaming := true
7978 session, err := client.CreateSession(ctx, &copilot.SessionConfig{
8079 OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
8180 Model: "claude-opus-4.6",
82- Streaming: &streaming ,
83- McpServers : map[string]interface{} {
84- "playwright": map[string]interface{} {
81+ Streaming: true ,
82+ MCPServers : map[string]copilot.MCPServerConfig {
83+ "playwright": {
8584 "type": "local",
8685 "command": "npx",
8786 "args": []string{"@playwright/mcp@latest"},
@@ -92,26 +91,22 @@ func main() {
9291 if err != nil {
9392 log.Fatal(err)
9493 }
95- defer session.Destroy ()
94+ defer session.Disconnect ()
9695
9796 // Set up streaming event handling
9897 done := make(chan struct{}, 1)
9998
10099 session.On(func(event copilot.SessionEvent) {
101- switch event.Type {
102- case "assistant.message.delta":
103- if event.Data.DeltaContent != nil {
104- fmt.Print(*event.Data.DeltaContent)
105- }
106- case "session.idle":
100+ switch d := event.Data.(type) {
101+ case *copilot.AssistantMessageDeltaData:
102+ fmt.Print(d.DeltaContent)
103+ case *copilot.SessionIdleData:
107104 select {
108105 case done <- struct{}{}:
109106 default:
110107 }
111- case "session.error":
112- if event.Data.Message != nil {
113- fmt.Printf("\nError: %s\n", *event.Data.Message)
114- }
108+ case *copilot.SessionErrorData:
109+ fmt.Printf("\nError: %s\n", d.Message)
115110 select {
116111 case done <- struct{}{}:
117112 default:
@@ -202,7 +197,7 @@ func main() {
202197## How it works
203198
2041991. **Playwright MCP server**: Configures a local MCP server running `@playwright/mcp` to provide browser automation tools
205- 2. **Streaming output**: Uses `Streaming: &streaming ` and `assistant.message.delta ` events for real-time token-by-token output
200+ 2. **Streaming output**: Uses `Streaming: true ` and `AssistantMessageDeltaData ` events for real-time token-by-token output
2062013. **Accessibility snapshot**: Playwright' s ` browser_snapshot` tool captures the full accessibility tree of the page
2072024. ** Structured report** : The prompt engineers a consistent WCAG-aligned report format with emoji severity indicators
2082035. ** Test generation** : Optionally detects the project language and generates Playwright accessibility tests
@@ -216,8 +211,8 @@ The recipe configures a local MCP server that runs alongside the session:
216211` ` ` go
217212session, err := client.CreateSession(ctx, & copilot.SessionConfig{
218213 OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
219- McpServers : map[string]interface{} {
220- " playwright" : map[string]interface{} {
214+ MCPServers : map[string]copilot.MCPServerConfig {
215+ " playwright" : {
221216 " type" : " local" ,
222217 " command" : " npx" ,
223218 " args" : []string{" @playwright/mcp@latest" },
@@ -235,12 +230,10 @@ Unlike `SendAndWait`, this recipe uses streaming for real-time output:
235230
236231` ` ` go
237232session.On(func(event copilot.SessionEvent) {
238- switch event.Type {
239- case " assistant.message.delta" :
240- if event.Data.DeltaContent ! = nil {
241- fmt.Print(* event.Data.DeltaContent)
242- }
243- case " session.idle" :
233+ switch d := event.Data.(type) {
234+ case * copilot.AssistantMessageDeltaData:
235+ fmt.Print(d.DeltaContent)
236+ case * copilot.SessionIdleData:
244237 done < - struct{}{}
245238 }
246239})
0 commit comments