Fix Go cookbook recipes to use correct SDK API

All 5 Go recipes and their markdown docs used incorrect API patterns
that don't match the real github.com/github/copilot-sdk/go v0.1.23:

- copilot.NewClient() -> copilot.NewClient(nil) (*ClientOptions param)
- client.Start() -> client.Start(ctx) (context.Context required)
- copilot.SessionConfig -> &copilot.SessionConfig (pointer required)
- session.On(func(event copilot.Event)) -> session.On(func(event copilot.SessionEvent))
- Type assertions -> event.Type string check + *event.Data.Content deref
- session.WaitForIdle() -> session.SendAndWait(ctx, ...) (WaitForIdle doesn't exist)
- copilot.SystemMessage -> copilot.SystemMessageConfig

All 5 recipes verified to compile against SDK v0.1.23.
This commit is contained in:
Anthony Shaw
2026-02-11 06:06:37 -08:00
parent 4555fee5d2
commit 5eb7adb376
10 changed files with 246 additions and 232 deletions

View File

@@ -1,34 +1,36 @@
package main
import (
"context"
"fmt"
"log"
"github.com/github/copilot-sdk/go"
copilot "github.com/github/copilot-sdk/go"
)
func main() {
client := copilot.NewClient()
ctx := context.Background()
client := copilot.NewClient(nil)
if err := client.Start(); err != nil {
if err := client.Start(ctx); err != nil {
log.Fatal(err)
}
defer client.Stop()
// Create multiple independent sessions
session1, err := client.CreateSession(copilot.SessionConfig{Model: "gpt-5"})
session1, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-5"})
if err != nil {
log.Fatal(err)
}
defer session1.Destroy()
session2, err := client.CreateSession(copilot.SessionConfig{Model: "gpt-5"})
session2, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-5"})
if err != nil {
log.Fatal(err)
}
defer session2.Destroy()
session3, err := client.CreateSession(copilot.SessionConfig{Model: "claude-sonnet-4.5"})
session3, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "claude-sonnet-4.5"})
if err != nil {
log.Fatal(err)
}
@@ -37,16 +39,16 @@ func main() {
fmt.Println("Created 3 independent sessions")
// Each session maintains its own conversation history
session1.Send(copilot.MessageOptions{Prompt: "You are helping with a Python project"})
session2.Send(copilot.MessageOptions{Prompt: "You are helping with a TypeScript project"})
session3.Send(copilot.MessageOptions{Prompt: "You are helping with a Go project"})
session1.Send(ctx, copilot.MessageOptions{Prompt: "You are helping with a Python project"})
session2.Send(ctx, copilot.MessageOptions{Prompt: "You are helping with a TypeScript project"})
session3.Send(ctx, copilot.MessageOptions{Prompt: "You are helping with a Go project"})
fmt.Println("Sent initial context to all sessions")
// Follow-up messages stay in their respective contexts
session1.Send(copilot.MessageOptions{Prompt: "How do I create a virtual environment?"})
session2.Send(copilot.MessageOptions{Prompt: "How do I set up tsconfig?"})
session3.Send(copilot.MessageOptions{Prompt: "How do I initialize a module?"})
session1.Send(ctx, copilot.MessageOptions{Prompt: "How do I create a virtual environment?"})
session2.Send(ctx, copilot.MessageOptions{Prompt: "How do I set up tsconfig?"})
session3.Send(ctx, copilot.MessageOptions{Prompt: "How do I initialize a module?"})
fmt.Println("Sent follow-up questions to each session")
fmt.Println("All sessions will be destroyed on exit")