Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions docs/auth/byok.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ asyncio.run(main())
<summary><strong>Node.js / TypeScript</strong></summary>

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

const FOUNDRY_MODEL_URL = "https://your-resource.openai.azure.com/openai/v1/";

Expand All @@ -76,6 +76,7 @@ const session = await client.createSession({
wireApi: "responses", // Use "completions" for older models
apiKey: process.env.FOUNDRY_API_KEY,
},
onPermissionRequest: approveAll
});

session.on("assistant.message", (event) => {
Expand Down Expand Up @@ -457,12 +458,14 @@ When using BYOK, the `model` parameter is **required**:
// ❌ Error: Model required with custom provider
const session = await client.createSession({
provider: { type: "openai", baseUrl: "..." },
onPermissionRequest: async () => ({ kind: "approved" }),
});

// ✅ Correct: Model specified
const session = await client.createSession({
model: "gpt-4", // Required!
provider: { type: "openai", baseUrl: "..." },
onPermissionRequest: async () => ({ kind: "approved" }),
});
```

Expand All @@ -472,7 +475,7 @@ For Azure OpenAI endpoints (`*.openai.azure.com`), use the correct type:

<!-- docs-validate: hidden -->
```typescript
import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";

const client = new CopilotClient();
const session = await client.createSession({
Expand All @@ -481,6 +484,7 @@ const session = await client.createSession({
type: "azure",
baseUrl: "https://my-resource.openai.azure.com",
},
onPermissionRequest: approveAll
});
```
<!-- /docs-validate: hidden -->
Expand All @@ -503,7 +507,7 @@ However, if your Azure AI Foundry deployment provides an OpenAI-compatible endpo

<!-- docs-validate: hidden -->
```typescript
import { CopilotClient } from "@github/copilot-sdk";
import { CopilotClient, approveAll } from "@github/copilot-sdk";

const client = new CopilotClient();
const session = await client.createSession({
Expand All @@ -512,6 +516,7 @@ const session = await client.createSession({
type: "openai",
baseUrl: "https://your-resource.openai.azure.com/openai/v1/",
},
onPermissionRequest: approveAll
});
```
<!-- /docs-validate: hidden -->
Expand Down
3 changes: 3 additions & 0 deletions docs/features/custom-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const session = await client.createSession({
},
],
agent: "researcher", // Pre-select the researcher agent
onPermissionRequest: async () => ({ kind: "approved" }),
});
```

Expand Down Expand Up @@ -639,6 +640,7 @@ const session = await client.createSession({
prompt: "You handle complex multi-step tasks using any available tools.",
},
],
onPermissionRequest: async () => ({ kind: "approved" }),
});
```

Expand All @@ -663,6 +665,7 @@ const session = await client.createSession({
},
},
],
onPermissionRequest: async () => ({ kind: "approved" }),
});
```

Expand Down
6 changes: 4 additions & 2 deletions docs/features/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The SDK supports two types of MCP servers:
### Node.js / TypeScript

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

const client = new CopilotClient();
const session = await client.createSession({
Expand All @@ -52,6 +52,7 @@ const session = await client.createSession({
tools: ["*"],
},
},
onPermissionRequest: approveAll
});
```

Expand Down Expand Up @@ -162,7 +163,7 @@ await using var session = await client.CreateSessionAsync(new SessionConfig
Here's a complete working example using the official [`@modelcontextprotocol/server-filesystem`](https://www.npmjs.com/package/@modelcontextprotocol/server-filesystem) MCP server:

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

async function main() {
const client = new CopilotClient();
Expand All @@ -177,6 +178,7 @@ async function main() {
tools: ["*"],
},
},
onPermissionRequest: approveAll
});

console.log("Session created:", session.sessionId);
Expand Down
25 changes: 14 additions & 11 deletions docs/features/session-persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ The key to resumable sessions is providing your own `session_id`. Without one, t
### TypeScript

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

const client = new CopilotClient();

// Create a session with a meaningful ID
const session = await client.createSession({
sessionId: "user-123-task-456",
model: "gpt-5.2-codex",
onPermissionRequest: approveAll
});

// Do some work...
Expand Down Expand Up @@ -134,10 +135,10 @@ flowchart LR
subgraph Day1["Day 1"]
A1[Client A:<br/>createSession] --> A2[Work...]
end

A2 --> S[(💾 Storage:<br/>~/.copilot/session-state/)]
S --> B1

subgraph Day2["Day 2"]
B1[Client B:<br/>resumeSession] --> B2[Continue]
end
Expand Down Expand Up @@ -275,6 +276,7 @@ const session = await client.createSession({
apiKey: process.env.AZURE_OPENAI_KEY,
deploymentId: "my-gpt-deployment",
},
onPermissionRequest: async () => ({ kind: "approved" }),
});

// When resuming, you MUST re-provide the provider config
Expand Down Expand Up @@ -376,7 +378,7 @@ const repoSessions = await client.listSessions({ repository: "owner/repo" });
async function cleanupExpiredSessions(maxAgeMs: number) {
const sessions = await client.listSessions();
const now = Date.now();

for (const session of sessions) {
const age = now - new Date(session.createdAt).getTime();
if (age > maxAgeMs) {
Expand All @@ -398,7 +400,7 @@ When a task completes, disconnect from the session explicitly rather than waitin
try {
// Do work...
await session.sendAndWait({ prompt: "Complete the task" });

// Task complete — release in-memory resources (session can be resumed later)
await session.disconnect();
} catch (error) {
Expand Down Expand Up @@ -495,11 +497,11 @@ async function resumeSessionWithAuth(
): Promise<Session> {
// Parse user from session ID
const [sessionUserId] = sessionId.split("-");

if (sessionUserId !== currentUserId) {
throw new Error("Access denied: session belongs to another user");
}

return client.resumeSession(sessionId);
}
```
Expand Down Expand Up @@ -533,10 +535,10 @@ flowchart LR
subgraph Before["Container A"]
CLI1[CLI + Session X]
end

CLI1 --> |persist| Azure[(☁️ Azure File Share)]
Azure --> |restore| CLI2

subgraph After["Container B (restart)"]
CLI2[CLI + Session X]
end
Expand All @@ -556,6 +558,7 @@ const session = await client.createSession({
backgroundCompactionThreshold: 0.80, // Start compaction at 80% context
bufferExhaustionThreshold: 0.95, // Block at 95% if needed
},
onPermissionRequest: async () => ({ kind: "approved" }),
});
```

Expand Down Expand Up @@ -586,11 +589,11 @@ async function withSessionLock<T>(
): Promise<T> {
const lockKey = `session-lock:${sessionId}`;
const acquired = await redis.set(lockKey, "locked", "NX", "EX", 300);

if (!acquired) {
throw new Error("Session is in use by another client");
}

try {
return await fn();
} finally {
Expand Down
1 change: 1 addition & 0 deletions docs/features/skills.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Disable specific skills while keeping others active:
const session = await client.createSession({
skillDirectories: ["./skills"],
disabledSkills: ["experimental-feature", "deprecated-tool"],
onPermissionRequest: async () => ({ kind: "approved" }),
});
```

Expand Down
2 changes: 1 addition & 1 deletion docs/features/steering-and-queueing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Steering sends a message that is injected directly into the agent's current turn
<summary><strong>Node.js / TypeScript</strong></summary>

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice there's a mix of approveAll and inline handlers (async () => ({ kind: "approved" })) across many of these docs. For this one in particular it seems strange to import approveAll and then not use it.

Would you be willing to check across all these docs and standardize on one approach? Ideally let's use the approveAll import for all of them.


const client = new CopilotClient();
await client.start();
Expand Down
15 changes: 10 additions & 5 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ Create a new file and add the following code. This is the simplest way to use th
Create `index.ts`:

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

const client = new CopilotClient();
const session = await client.createSession({ model: "gpt-4.1" });
const session = await client.createSession({ model: "gpt-4.1", onPermissionRequest: approveAll });

const response = await session.sendAndWait({ prompt: "What is 2 + 2?" });
console.log(response?.data.content);
Expand Down Expand Up @@ -249,7 +249,7 @@ const client = new CopilotClient();
const session = await client.createSession({
model: "gpt-4.1",
streaming: true,
});
}, onPermissionRequest: approveAll);
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This createSession call is syntactically invalid: onPermissionRequest is being passed outside the config object (}, onPermissionRequest: approveAll);). Move onPermissionRequest: approveAll inside the object literal, and ensure approveAll is imported in this snippet (the import currently only brings in CopilotClient).

Copilot uses AI. Check for mistakes.

// Listen for response chunks
session.on("assistant.message_delta", (event) => {
Expand Down Expand Up @@ -595,7 +595,7 @@ Now for the powerful part. Let's give Copilot the ability to call your code by d
Update `index.ts`:

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

// Define a tool that Copilot can call
const getWeather = defineTool("get_weather", {
Expand All @@ -622,6 +622,7 @@ const session = await client.createSession({
model: "gpt-4.1",
streaming: true,
tools: [getWeather],
onPermissionRequest: approveAll
});

session.on("assistant.message_delta", (event) => {
Expand Down Expand Up @@ -845,7 +846,7 @@ Let's put it all together into a useful interactive assistant:
<summary><strong>Node.js / TypeScript</strong></summary>

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

const getWeather = defineTool("get_weather", {
Expand All @@ -870,6 +871,7 @@ const session = await client.createSession({
model: "gpt-4.1",
streaming: true,
tools: [getWeather],
onPermissionRequest: approveAll
});

session.on("assistant.message_delta", (event) => {
Expand Down Expand Up @@ -1211,6 +1213,7 @@ const session = await client.createSession({
url: "https://api.githubcopilot.com/mcp/",
},
},
onPermissionRequest: async () => ({ kind: "approved" }),
});
```

Expand All @@ -1228,6 +1231,7 @@ const session = await client.createSession({
description: "Reviews pull requests for best practices",
prompt: "You are an expert code reviewer. Focus on security, performance, and maintainability.",
}],
onPermissionRequest: async () => ({ kind: "approved" }),
});
```

Expand All @@ -1242,6 +1246,7 @@ const session = await client.createSession({
systemMessage: {
content: "You are a helpful assistant for our engineering team. Always be concise.",
},
onPermissionRequest: async () => ({ kind: "approved" }),
});
```

Expand Down
Loading
Loading