Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion cookbook/copilot-sdk/dotnet/persisting-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ await using var client = new CopilotClient();
await client.StartAsync();

// Resume the previous session
var session = await client.ResumeSessionAsync("user-123-conversation");
var session = await client.ResumeSessionAsync("user-123-conversation", new ResumeSessionConfig { OnPermissionRequest = PermissionHandler.ApproveAll });

// Previous context is restored
await session.SendAsync(new MessageOptions { Prompt = "What were we discussing?" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Console.WriteLine("Session destroyed (state persisted)");

// Resume the previous session
var resumed = await client.ResumeSessionAsync("user-123-conversation");
var resumed = await client.ResumeSessionAsync("user-123-conversation", new ResumeSessionConfig { OnPermissionRequest = PermissionHandler.ApproveAll });
Console.WriteLine($"Resumed: {resumed.SessionId}");

await resumed.SendAsync(new MessageOptions { Prompt = "What were we discussing?" });
Expand Down
2 changes: 2 additions & 0 deletions cookbook/copilot-sdk/go/accessibility-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func main() {

streaming := true
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Model: "claude-opus-4.6",
Streaming: &streaming,
McpServers: map[string]interface{}{
Expand Down Expand Up @@ -214,6 +215,7 @@ The recipe configures a local MCP server that runs alongside the session:

```go
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
McpServers: map[string]interface{}{
"playwright": map[string]interface{}{
"type": "local",
Expand Down
4 changes: 3 additions & 1 deletion cookbook/copilot-sdk/go/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func main() {
defer client.Stop()

session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Model: "gpt-5",
})
if err != nil {
Expand Down Expand Up @@ -177,7 +178,8 @@ func doWork() error {
}
defer client.Stop()

session, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-5"})
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll, Model: "gpt-5"})
if err != nil {
return fmt.Errorf("failed to create session: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions cookbook/copilot-sdk/go/managing-local-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func main() {

// Create session
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Model: "gpt-5",
})
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions cookbook/copilot-sdk/go/multiple-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ func main() {
defer client.Stop()

// Create multiple independent sessions
session1, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-5"})
session1, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll, Model: "gpt-5"})
if err != nil {
log.Fatal(err)
}
defer session1.Destroy()

session2, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-5"})
session2, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll, Model: "gpt-5"})
if err != nil {
log.Fatal(err)
}
defer session2.Destroy()

session3, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "claude-sonnet-4.5"})
session3, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll, Model: "claude-sonnet-4.5"})
if err != nil {
log.Fatal(err)
}
Expand All @@ -70,6 +73,7 @@ Use custom IDs for easier tracking:

```go
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
SessionID: "user-123-chat",
Model: "gpt-5",
})
Expand Down
3 changes: 2 additions & 1 deletion cookbook/copilot-sdk/go/persisting-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func main() {

// Create session with a memorable ID
session, _ := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
SessionID: "user-123-conversation",
Model: "gpt-5",
})
Expand All @@ -55,7 +56,7 @@ client.Start(ctx)
defer client.Stop()

// Resume the previous session
session, _ := client.ResumeSession(ctx, "user-123-conversation")
session, _ := client.ResumeSession(ctx, "user-123-conversation", &copilot.ResumeSessionConfig{OnPermissionRequest: copilot.PermissionHandler.ApproveAll})

// Previous context is restored
session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "What were we discussing?"})
Expand Down
1 change: 1 addition & 0 deletions cookbook/copilot-sdk/go/pr-visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func main() {

cwd, _ := os.Getwd()
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Model: "gpt-5",
SystemMessage: &copilot.SystemMessageConfig{
Content: fmt.Sprintf(`
Expand Down
1 change: 1 addition & 0 deletions cookbook/copilot-sdk/go/ralph-loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func ralphLoop(ctx context.Context, promptFile string, maxIterations int) error

// Fresh session each iteration — context isolation is the point
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Model: "gpt-5.1-codex-mini",
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cookbook/copilot-sdk/go/recipe/accessibility-report.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func main() {

streaming := true
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Model: "claude-opus-4.6",
Streaming: &streaming,
McpServers: map[string]interface{}{
Expand Down
1 change: 1 addition & 0 deletions cookbook/copilot-sdk/go/recipe/error-handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func main() {
defer client.Stop()

session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Model: "gpt-5",
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cookbook/copilot-sdk/go/recipe/managing-local-files.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {

// Create session
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Model: "gpt-5",
})
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions cookbook/copilot-sdk/go/recipe/multiple-sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ func main() {
defer client.Stop()

// Create multiple independent sessions
session1, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-5"})
session1, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll, Model: "gpt-5"})
if err != nil {
log.Fatal(err)
}
defer session1.Destroy()

session2, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-5"})
session2, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll, Model: "gpt-5"})
if err != nil {
log.Fatal(err)
}
defer session2.Destroy()

session3, err := client.CreateSession(ctx, &copilot.SessionConfig{Model: "claude-sonnet-4.5"})
session3, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll, Model: "claude-sonnet-4.5"})
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cookbook/copilot-sdk/go/recipe/persisting-sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func main() {

// Create session with a memorable ID
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
SessionID: "user-123-conversation",
Model: "gpt-5",
})
Expand All @@ -36,7 +37,7 @@ func main() {
fmt.Println("Session destroyed (state persisted)")

// Resume the previous session
resumed, err := client.ResumeSession(ctx, "user-123-conversation")
resumed, err := client.ResumeSession(ctx, "user-123-conversation", &copilot.ResumeSessionConfig{OnPermissionRequest: copilot.PermissionHandler.ApproveAll})
if err != nil {
log.Fatal(err)
}
Expand Down
1 change: 1 addition & 0 deletions cookbook/copilot-sdk/go/recipe/pr-visualization.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func main() {

cwd, _ := os.Getwd()
session, err := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Model: "gpt-5",
SystemMessage: &copilot.SystemMessageConfig{
Content: fmt.Sprintf(`
Expand Down
4 changes: 3 additions & 1 deletion cookbook/copilot-sdk/nodejs/accessibility-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ npx tsx accessibility-report.ts
```typescript
#!/usr/bin/env npx tsx

import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";
import * as readline from "node:readline";

// ============================================================================
Expand Down Expand Up @@ -73,6 +73,7 @@ async function main() {
const client = new CopilotClient();

const session = await client.createSession({
onPermissionRequest: approveAll,
model: "claude-opus-4.6",
streaming: true,
mcpServers: {
Expand Down Expand Up @@ -191,6 +192,7 @@ The recipe configures a local MCP server that runs alongside the session:

```typescript
const session = await client.createSession({
onPermissionRequest: approveAll,
mcpServers: {
playwright: {
type: "local",
Expand Down
14 changes: 10 additions & 4 deletions cookbook/copilot-sdk/nodejs/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ You need to handle various error conditions like connection failures, timeouts,
## Basic try-catch

```typescript
import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";

const client = new CopilotClient();

try {
await client.start();
const session = await client.createSession({ model: "gpt-5" });
const session = await client.createSession({
onPermissionRequest: approveAll,
model: "gpt-5" });

const response = await session.sendAndWait({ prompt: "Hello!" });
console.log(response?.data.content);
Expand Down Expand Up @@ -55,7 +57,9 @@ try {
## Timeout handling

```typescript
const session = await client.createSession({ model: "gpt-5" });
const session = await client.createSession({
onPermissionRequest: approveAll,
model: "gpt-5" });

try {
// sendAndWait with timeout (in milliseconds)
Expand All @@ -79,7 +83,9 @@ try {
## Aborting a request

```typescript
const session = await client.createSession({ model: "gpt-5" });
const session = await client.createSession({
onPermissionRequest: approveAll,
model: "gpt-5" });

// Start a request
session.send({ prompt: "Write a very long story..." });
Expand Down
3 changes: 2 additions & 1 deletion cookbook/copilot-sdk/nodejs/managing-local-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You have a folder with many files and want to organize them into subfolders base
## Example code

```typescript
import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";
import * as os from "node:os";
import * as path from "node:path";

Expand All @@ -27,6 +27,7 @@ await client.start();

// Create session
const session = await client.createSession({
onPermissionRequest: approveAll,
model: "gpt-5",
});

Expand Down
15 changes: 11 additions & 4 deletions cookbook/copilot-sdk/nodejs/multiple-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ You need to run multiple conversations in parallel, each with its own context an
## Node.js

```typescript
import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";

const client = new CopilotClient();
await client.start();

// Create multiple independent sessions
const session1 = await client.createSession({ model: "gpt-5" });
const session2 = await client.createSession({ model: "gpt-5" });
const session3 = await client.createSession({ model: "claude-sonnet-4.5" });
const session1 = await client.createSession({
onPermissionRequest: approveAll,
model: "gpt-5" });
const session2 = await client.createSession({
onPermissionRequest: approveAll,
model: "gpt-5" });
const session3 = await client.createSession({
onPermissionRequest: approveAll,
model: "claude-sonnet-4.5" });

// Each session maintains its own conversation history
await session1.sendAndWait({ prompt: "You are helping with a Python project" });
Expand All @@ -50,6 +56,7 @@ Use custom IDs for easier tracking:

```typescript
const session = await client.createSession({
onPermissionRequest: approveAll,
sessionId: "user-123-chat",
model: "gpt-5",
});
Expand Down
5 changes: 3 additions & 2 deletions cookbook/copilot-sdk/nodejs/persisting-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ You want users to be able to continue a conversation even after closing and reop
### Creating a session with a custom ID

```typescript
import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";

const client = new CopilotClient();
await client.start();

// Create session with a memorable ID
const session = await client.createSession({
onPermissionRequest: approveAll,
sessionId: "user-123-conversation",
model: "gpt-5",
});
Expand All @@ -45,7 +46,7 @@ const client = new CopilotClient();
await client.start();

// Resume the previous session
const session = await client.resumeSession("user-123-conversation");
const session = await client.resumeSession("user-123-conversation", { onPermissionRequest: approveAll });

// Previous context is restored
await session.sendAndWait({ prompt: "What were we discussing?" });
Expand Down
3 changes: 2 additions & 1 deletion cookbook/copilot-sdk/nodejs/pr-visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ npx tsx pr-visualization.ts --repo github/copilot-sdk

import { execSync } from "node:child_process";
import * as readline from "node:readline";
import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";

// ============================================================================
// Git & GitHub Detection
Expand Down Expand Up @@ -138,6 +138,7 @@ async function main() {
const client = new CopilotClient({ logLevel: "error" });

const session = await client.createSession({
onPermissionRequest: approveAll,
model: "gpt-5",
systemMessage: {
content: `
Expand Down
6 changes: 4 additions & 2 deletions cookbook/copilot-sdk/nodejs/ralph-loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The minimal Ralph loop — the SDK equivalent of `while :; do cat PROMPT.md | co
```typescript
import { readFile } from "fs/promises";
import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";
async function ralphLoop(promptFile: string, maxIterations: number = 50) {
const client = new CopilotClient();
Expand All @@ -56,7 +56,9 @@ async function ralphLoop(promptFile: string, maxIterations: number = 50) {
console.log(`\n=== Iteration ${i}/${maxIterations} ===`);
// Fresh session each iteration — context isolation is the point
const session = await client.createSession({ model: "gpt-5.1-codex-mini" });
const session = await client.createSession({
onPermissionRequest: approveAll,
model: "gpt-5.1-codex-mini" });
try {
await session.sendAndWait({ prompt }, 600_000);
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env tsx

import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";
import * as readline from "node:readline";

// ============================================================================
Expand Down Expand Up @@ -38,6 +38,7 @@ async function main() {
const client = new CopilotClient();

const session = await client.createSession({
onPermissionRequest: approveAll,
model: "claude-opus-4.6",
streaming: true,
mcpServers: {
Expand Down
Loading
Loading