Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
.github/workflows/*.lock.yml linguist-generated=true merge=ours
.github/workflows/*.lock.yml linguist-generated=true merge=ours

# Generated files — keep LF line endings so codegen output is deterministic across platforms.
nodejs/src/generated/* eol=lf linguist-generated=true
dotnet/src/Generated/* eol=lf linguist-generated=true
python/copilot/generated/* eol=lf linguist-generated=true
go/generated_session_events.go eol=lf linguist-generated=true
go/rpc/generated_rpc.go eol=lf linguist-generated=true
5 changes: 0 additions & 5 deletions .github/workflows/codegen-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ jobs:

- name: Check for uncommitted changes
run: |
# TODO: Remove this when https://github.com/github/copilot-sdk/issues/1031 is fixed
# Exclude go/generated_session_events.go from the check — it was intentionally
# reverted to avoid a breaking DataContent change (see #1031) and will be
# regenerated once that issue is resolved.
git checkout -- go/generated_session_events.go 2>/dev/null || true
if [ -n "$(git status --porcelain)" ]; then
echo "::error::Generated files are out of date. Run 'cd scripts/codegen && npm run generate' and commit the changes."
git diff --stat
Expand Down
4 changes: 3 additions & 1 deletion docs/auth/byok.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func main() {
panic(err)
}

fmt.Println(*response.Data.Content)
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
fmt.Println(d.Content)
}
}
```

Expand Down
44 changes: 22 additions & 22 deletions docs/features/custom-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,17 +506,17 @@ func main() {
})

session.On(func(event copilot.SessionEvent) {
switch event.Type {
case "subagent.started":
fmt.Printf("▶ Sub-agent started: %s\n", *event.Data.AgentDisplayName)
fmt.Printf(" Description: %s\n", *event.Data.AgentDescription)
fmt.Printf(" Tool call ID: %s\n", *event.Data.ToolCallID)
case "subagent.completed":
fmt.Printf("✅ Sub-agent completed: %s\n", *event.Data.AgentDisplayName)
case "subagent.failed":
fmt.Printf("❌ Sub-agent failed: %s — %v\n", *event.Data.AgentDisplayName, event.Data.Error)
case "subagent.selected":
fmt.Printf("🎯 Agent selected: %s\n", *event.Data.AgentDisplayName)
switch d := event.Data.(type) {
case *copilot.SubagentStartedData:
fmt.Printf("▶ Sub-agent started: %s\n", d.AgentDisplayName)
fmt.Printf(" Description: %s\n", d.AgentDescription)
fmt.Printf(" Tool call ID: %s\n", d.ToolCallID)
case *copilot.SubagentCompletedData:
fmt.Printf("✅ Sub-agent completed: %s\n", d.AgentDisplayName)
case *copilot.SubagentFailedData:
fmt.Printf("❌ Sub-agent failed: %s — %v\n", d.AgentDisplayName, d.Error)
case *copilot.SubagentSelectedData:
fmt.Printf("🎯 Agent selected: %s\n", d.AgentDisplayName)
}
})

Expand All @@ -530,17 +530,17 @@ func main() {

```go
session.On(func(event copilot.SessionEvent) {
switch event.Type {
case "subagent.started":
fmt.Printf("▶ Sub-agent started: %s\n", *event.Data.AgentDisplayName)
fmt.Printf(" Description: %s\n", *event.Data.AgentDescription)
fmt.Printf(" Tool call ID: %s\n", *event.Data.ToolCallID)
case "subagent.completed":
fmt.Printf("✅ Sub-agent completed: %s\n", *event.Data.AgentDisplayName)
case "subagent.failed":
fmt.Printf("❌ Sub-agent failed: %s — %v\n", *event.Data.AgentDisplayName, event.Data.Error)
case "subagent.selected":
fmt.Printf("🎯 Agent selected: %s\n", *event.Data.AgentDisplayName)
switch d := event.Data.(type) {
case *copilot.SubagentStartedData:
fmt.Printf("▶ Sub-agent started: %s\n", d.AgentDisplayName)
fmt.Printf(" Description: %s\n", d.AgentDescription)
fmt.Printf(" Tool call ID: %s\n", d.ToolCallID)
case *copilot.SubagentCompletedData:
fmt.Printf("✅ Sub-agent completed: %s\n", d.AgentDisplayName)
case *copilot.SubagentFailedData:
fmt.Printf("❌ Sub-agent failed: %s — %v\n", d.AgentDisplayName, d.Error)
case *copilot.SubagentSelectedData:
fmt.Printf("🎯 Agent selected: %s\n", d.AgentDisplayName)
}
})

Expand Down
8 changes: 4 additions & 4 deletions docs/features/streaming-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func main() {
})

session.On(func(event copilot.SessionEvent) {
if event.Type == "assistant.message_delta" {
fmt.Print(*event.Data.DeltaContent)
if d, ok := event.Data.(*copilot.AssistantMessageDeltaData); ok {
fmt.Print(d.DeltaContent)
}
})
_ = session
Expand All @@ -148,8 +148,8 @@ func main() {

```go
session.On(func(event copilot.SessionEvent) {
if event.Type == "assistant.message_delta" {
fmt.Print(*event.Data.DeltaContent)
if d, ok := event.Data.(*copilot.AssistantMessageDeltaData); ok {
fmt.Print(d.DeltaContent)
}
})
```
Expand Down
49 changes: 28 additions & 21 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ func main() {
log.Fatal(err)
}

fmt.Println(*response.Data.Content)
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
fmt.Println(d.Content)
}
os.Exit(0)
}
```
Expand Down Expand Up @@ -406,10 +408,11 @@ func main() {

// Listen for response chunks
session.On(func(event copilot.SessionEvent) {
if event.Type == "assistant.message_delta" {
fmt.Print(*event.Data.DeltaContent)
}
if event.Type == "session.idle" {
switch d := event.Data.(type) {
case *copilot.AssistantMessageDeltaData:
fmt.Print(d.DeltaContent)
case *copilot.SessionIdleData:
_ = d
fmt.Println()
}
})
Expand Down Expand Up @@ -604,10 +607,12 @@ func main() {

// Filter by event type in your handler
session.On(func(event copilot.SessionEvent) {
if event.Type == "session.idle" {
switch d := event.Data.(type) {
case *copilot.SessionIdleData:
_ = d
fmt.Println("Session is idle")
} else if event.Type == "assistant.message" {
fmt.Println("Message:", *event.Data.Content)
case *copilot.AssistantMessageData:
fmt.Println("Message:", d.Content)
}
})

Expand All @@ -625,10 +630,12 @@ unsubscribe := session.On(func(event copilot.SessionEvent) {

// Filter by event type in your handler
session.On(func(event copilot.SessionEvent) {
if event.Type == "session.idle" {
switch d := event.Data.(type) {
case *copilot.SessionIdleData:
_ = d
fmt.Println("Session is idle")
} else if event.Type == "assistant.message" {
fmt.Println("Message:", *event.Data.Content)
case *copilot.AssistantMessageData:
fmt.Println("Message:", d.Content)
}
})

Expand Down Expand Up @@ -897,10 +904,11 @@ func main() {
}

session.On(func(event copilot.SessionEvent) {
if event.Type == "assistant.message_delta" {
fmt.Print(*event.Data.DeltaContent)
}
if event.Type == "session.idle" {
switch d := event.Data.(type) {
case *copilot.AssistantMessageDeltaData:
fmt.Print(d.DeltaContent)
case *copilot.SessionIdleData:
_ = d
fmt.Println()
}
})
Expand Down Expand Up @@ -1251,12 +1259,11 @@ func main() {
}

session.On(func(event copilot.SessionEvent) {
if event.Type == "assistant.message_delta" {
if event.Data.DeltaContent != nil {
fmt.Print(*event.Data.DeltaContent)
}
}
if event.Type == "session.idle" {
switch d := event.Data.(type) {
case *copilot.AssistantMessageDeltaData:
fmt.Print(d.DeltaContent)
case *copilot.SessionIdleData:
_ = d
fmt.Println()
}
})
Expand Down
8 changes: 6 additions & 2 deletions docs/setup/bundled-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func main() {

session, _ := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-4.1"})
response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Hello!"})
fmt.Println(*response.Data.Content)
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
fmt.Println(d.Content)
}
}
```
<!-- /docs-validate: hidden -->
Expand All @@ -146,7 +148,9 @@ defer client.Stop()

session, _ := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-4.1"})
response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Hello!"})
fmt.Println(*response.Data.Content)
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
fmt.Println(d.Content)
}
```

</details>
Expand Down
8 changes: 6 additions & 2 deletions docs/setup/local-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func main() {

session, _ := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-4.1"})
response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Hello!"})
fmt.Println(*response.Data.Content)
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
fmt.Println(d.Content)
}
}
```
<!-- /docs-validate: hidden -->
Expand All @@ -105,7 +107,9 @@ defer client.Stop()

session, _ := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-4.1"})
response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Hello!"})
fmt.Println(*response.Data.Content)
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
fmt.Println(d.Content)
}
```

</details>
Expand Down
38 changes: 14 additions & 24 deletions go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ func main() {
// Set up event handler
done := make(chan bool)
session.On(func(event copilot.SessionEvent) {
if event.Type == "assistant.message" {
if event.Data.Content != nil && event.Data.Content.String != nil {
fmt.Println(*event.Data.Content.String)
}
}
if event.Type == "session.idle" {
switch d := event.Data.(type) {
case *copilot.AssistantMessageData:
fmt.Println(d.Content)
case *copilot.SessionIdleData:
close(done)
}
})
Expand Down Expand Up @@ -404,30 +402,22 @@ func main() {
done := make(chan bool)

session.On(func(event copilot.SessionEvent) {
if event.Type == "assistant.message_delta" {
switch d := event.Data.(type) {
case *copilot.AssistantMessageDeltaData:
// Streaming message chunk - print incrementally
if event.Data.DeltaContent != nil {
fmt.Print(*event.Data.DeltaContent)
}
} else if event.Type == "assistant.reasoning_delta" {
fmt.Print(d.DeltaContent)
case *copilot.AssistantReasoningDeltaData:
// Streaming reasoning chunk (if model supports reasoning)
if event.Data.DeltaContent != nil {
fmt.Print(*event.Data.DeltaContent)
}
} else if event.Type == "assistant.message" {
fmt.Print(d.DeltaContent)
case *copilot.AssistantMessageData:
// Final message - complete content
fmt.Println("\n--- Final message ---")
if event.Data.Content != nil && event.Data.Content.String != nil {
fmt.Println(*event.Data.Content.String)
}
} else if event.Type == "assistant.reasoning" {
fmt.Println(d.Content)
case *copilot.AssistantReasoningData:
// Final reasoning content (if model supports reasoning)
fmt.Println("--- Reasoning ---")
if event.Data.Content != nil && event.Data.Content.String != nil {
fmt.Println(*event.Data.Content.String)
}
}
if event.Type == "session.idle" {
fmt.Println(d.Content)
case *copilot.SessionIdleData:
close(done)
}
})
Expand Down
4 changes: 2 additions & 2 deletions go/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// }
//
// session.On(func(event copilot.SessionEvent) {
// if event.Type == "assistant.message" {
// fmt.Println(event.Data.Content)
// if d, ok := event.Data.(*copilot.AssistantMessageData); ok {
// fmt.Println(d.Content)
// }
// })
//
Expand Down
Loading
Loading