Skip to content

Commit 2d021ac

Browse files
committed
Add onPermissionRequest handler to session creation across multiple files
1 parent 47cb899 commit 2d021ac

22 files changed

Lines changed: 161 additions & 72 deletions

docs/auth/byok.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const session = await client.createSession({
7979
wireApi: "responses", // Use "completions" for older models
8080
apiKey: process.env.FOUNDRY_API_KEY,
8181
},
82+
onPermissionRequest: async () => ({ kind: "approved" }),
8283
});
8384

8485
session.on("assistant.message", (event) => {
@@ -350,12 +351,14 @@ When using BYOK, the `model` parameter is **required**:
350351
// ❌ Error: Model required with custom provider
351352
const session = await client.createSession({
352353
provider: { type: "openai", baseUrl: "..." },
354+
onPermissionRequest: async () => ({ kind: "approved" }),
353355
});
354356

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

docs/compatibility.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ const session = await client.createSession({
158158
backgroundCompactionThreshold: 0.80, // Start background compaction at 80% context utilization
159159
bufferExhaustionThreshold: 0.95, // Block and compact at 95% context utilization
160160
},
161+
onPermissionRequest: async () => ({ kind: "approved" }),
161162
});
162163
```
163164

docs/debugging.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,9 @@ const client = new CopilotClient({
376376
```typescript
377377
const session = await client.createSession({
378378
tools: [myTool],
379+
onPermissionRequest: async () => ({ kind: "approved" }),
379380
});
380-
381+
381382
// Check registered tools
382383
console.log("Registered tools:", session.getTools?.());
383384
```

docs/getting-started.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Create `index.ts`:
105105
import { CopilotClient } from "@github/copilot-sdk";
106106

107107
const client = new CopilotClient();
108-
const session = await client.createSession({ model: "gpt-4.1" });
108+
const session = await client.createSession({ model: "gpt-4.1", onPermissionRequest: async () => ({ kind: "approved" }) });
109109

110110
const response = await session.sendAndWait({ prompt: "What is 2 + 2?" });
111111
console.log(response?.data.content);
@@ -248,6 +248,7 @@ const client = new CopilotClient();
248248
const session = await client.createSession({
249249
model: "gpt-4.1",
250250
streaming: true,
251+
onPermissionRequest: async () => ({ kind: "approved" }),
251252
});
252253

253254
// Listen for response chunks
@@ -624,6 +625,7 @@ const session = await client.createSession({
624625
model: "gpt-4.1",
625626
streaming: true,
626627
tools: [getWeather],
628+
onPermissionRequest: async () => ({ kind: "approved" }),
627629
});
628630

629631
session.on("assistant.message_delta", (event) => {
@@ -876,6 +878,7 @@ const session = await client.createSession({
876878
model: "gpt-4.1",
877879
streaming: true,
878880
tools: [getWeather],
881+
onPermissionRequest: async () => ({ kind: "approved" }),
879882
});
880883

881884
session.on("assistant.message_delta", (event) => {
@@ -1221,6 +1224,7 @@ const session = await client.createSession({
12211224
url: "https://api.githubcopilot.com/mcp/",
12221225
},
12231226
},
1227+
onPermissionRequest: async () => ({ kind: "approved" }),
12241228
});
12251229
```
12261230

@@ -1238,6 +1242,7 @@ const session = await client.createSession({
12381242
description: "Reviews pull requests for best practices",
12391243
prompt: "You are an expert code reviewer. Focus on security, performance, and maintainability.",
12401244
}],
1245+
onPermissionRequest: async () => ({ kind: "approved" }),
12411246
});
12421247
```
12431248

@@ -1250,6 +1255,7 @@ const session = await client.createSession({
12501255
systemMessage: {
12511256
content: "You are a helpful assistant for our engineering team. Always be concise.",
12521257
},
1258+
onPermissionRequest: async () => ({ kind: "approved" }),
12531259
});
12541260
```
12551261

docs/guides/session-persistence.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const client = new CopilotClient();
3434
const session = await client.createSession({
3535
sessionId: "user-123-task-456",
3636
model: "gpt-5.2-codex",
37+
onPermissionRequest: async () => ({ kind: "approved" }),
3738
});
3839

3940
// Do some work...
@@ -111,10 +112,10 @@ flowchart LR
111112
subgraph Day1["Day 1"]
112113
A1[Client A:<br/>createSession] --> A2[Work...]
113114
end
114-
115+
115116
A2 --> S[(💾 Storage:<br/>~/.copilot/session-state/)]
116117
S --> B1
117-
118+
118119
subgraph Day2["Day 2"]
119120
B1[Client B:<br/>resumeSession] --> B2[Continue]
120121
end
@@ -210,6 +211,7 @@ const session = await client.createSession({
210211
apiKey: process.env.AZURE_OPENAI_KEY,
211212
deploymentId: "my-gpt-deployment",
212213
},
214+
onPermissionRequest: async () => ({ kind: "approved" }),
213215
});
214216

215217
// When resuming, you MUST re-provide the provider config
@@ -311,7 +313,7 @@ const repoSessions = await client.listSessions({ repository: "owner/repo" });
311313
async function cleanupExpiredSessions(maxAgeMs: number) {
312314
const sessions = await client.listSessions();
313315
const now = Date.now();
314-
316+
315317
for (const session of sessions) {
316318
const age = now - new Date(session.createdAt).getTime();
317319
if (age > maxAgeMs) {
@@ -333,7 +335,7 @@ When a task completes, destroy the session explicitly rather than waiting for ti
333335
try {
334336
// Do work...
335337
await session.sendAndWait({ prompt: "Complete the task" });
336-
338+
337339
// Task complete - clean up
338340
await session.destroy();
339341
} catch (error) {
@@ -408,11 +410,11 @@ async function resumeSessionWithAuth(
408410
): Promise<Session> {
409411
// Parse user from session ID
410412
const [sessionUserId] = sessionId.split("-");
411-
413+
412414
if (sessionUserId !== currentUserId) {
413415
throw new Error("Access denied: session belongs to another user");
414416
}
415-
417+
416418
return client.resumeSession(sessionId);
417419
}
418420
```
@@ -446,10 +448,10 @@ flowchart LR
446448
subgraph Before["Container A"]
447449
CLI1[CLI + Session X]
448450
end
449-
451+
450452
CLI1 --> |persist| Azure[(☁️ Azure File Share)]
451453
Azure --> |restore| CLI2
452-
454+
453455
subgraph After["Container B (restart)"]
454456
CLI2[CLI + Session X]
455457
end
@@ -469,6 +471,7 @@ const session = await client.createSession({
469471
backgroundCompactionThreshold: 0.80, // Start compaction at 80% context
470472
bufferExhaustionThreshold: 0.95, // Block at 95% if needed
471473
},
474+
onPermissionRequest: async () => ({ kind: "approved" }),
472475
});
473476
```
474477

@@ -499,11 +502,11 @@ async function withSessionLock<T>(
499502
): Promise<T> {
500503
const lockKey = `session-lock:${sessionId}`;
501504
const acquired = await redis.set(lockKey, "locked", "NX", "EX", 300);
502-
505+
503506
if (!acquired) {
504507
throw new Error("Session is in use by another client");
505508
}
506-
509+
507510
try {
508511
return await fn();
509512
} finally {

docs/guides/setup/azure-managed-identity.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ const session = await client.createSession({
145145
bearerToken: tokenResponse.token,
146146
wireApi: "responses",
147147
},
148+
onPermissionRequest: async () => ({ kind: "approved" }),
148149
});
149150

150151
const response = await session.sendAndWait({ prompt: "Hello!" });

docs/guides/setup/backend-services.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const client = new CopilotClient({
9999
const session = await client.createSession({
100100
sessionId: `user-${userId}-${Date.now()}`,
101101
model: "gpt-4.1",
102+
onPermissionRequest: async () => ({ kind: "approved" }),
102103
});
103104

104105
const response = await session.sendAndWait({ prompt: req.body.message });
@@ -213,6 +214,7 @@ app.post("/chat", authMiddleware, async (req, res) => {
213214
const session = await client.createSession({
214215
sessionId: `user-${req.user.id}-chat`,
215216
model: "gpt-4.1",
217+
onPermissionRequest: async () => ({ kind: "approved" }),
216218
});
217219

218220
const response = await session.sendAndWait({
@@ -239,6 +241,7 @@ const session = await client.createSession({
239241
baseUrl: "https://api.openai.com/v1",
240242
apiKey: process.env.OPENAI_API_KEY,
241243
},
244+
onPermissionRequest: async () => ({ kind: "approved" }),
242245
});
243246
```
244247

@@ -285,6 +288,7 @@ app.post("/api/chat", async (req, res) => {
285288
session = await client.createSession({
286289
sessionId,
287290
model: "gpt-4.1",
291+
onPermissionRequest: async () => ({ kind: "approved" }),
288292
});
289293
}
290294

@@ -312,6 +316,7 @@ async function processJob(job: Job) {
312316
const session = await client.createSession({
313317
sessionId: `job-${job.id}`,
314318
model: "gpt-4.1",
319+
onPermissionRequest: async () => ({ kind: "approved" }),
315320
});
316321

317322
const response = await session.sendAndWait({

docs/guides/setup/bundled-cli.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const client = new CopilotClient({
7272
cliPath: path.join(__dirname, "vendor", "copilot"),
7373
});
7474

75-
const session = await client.createSession({ model: "gpt-4.1" });
75+
const session = await client.createSession({ model: "gpt-4.1" }, onPermissionRequest: async () => ({ kind: "approved" }),);
7676
const response = await session.sendAndWait({ prompt: "Hello!" });
7777
console.log(response?.data.content);
7878

@@ -200,6 +200,7 @@ const session = await client.createSession({
200200
baseUrl: "https://api.openai.com/v1",
201201
apiKey: process.env.OPENAI_API_KEY,
202202
},
203+
onPermissionRequest: async () => ({ kind: "approved" }),
203204
});
204205
```
205206

@@ -219,6 +220,7 @@ const sessionId = `project-${projectName}`;
219220
const session = await client.createSession({
220221
sessionId,
221222
model: "gpt-4.1",
223+
onPermissionRequest: async () => ({ kind: "approved" }),
222224
});
223225

224226
// User closes app...

docs/guides/setup/byok.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const session = await client.createSession({
7878
baseUrl: "https://api.openai.com/v1",
7979
apiKey: process.env.OPENAI_API_KEY,
8080
},
81+
onPermissionRequest: async () => ({ kind: "approved" }),
8182
});
8283

8384
const response = await session.sendAndWait({ prompt: "Hello!" });
@@ -255,6 +256,7 @@ app.post("/chat", authMiddleware, async (req, res) => {
255256
baseUrl: "https://api.openai.com/v1",
256257
apiKey: process.env.OPENAI_API_KEY, // Your key, your billing
257258
},
259+
onPermissionRequest: async () => ({ kind: "approved" }),
258260
});
259261

260262
const response = await session.sendAndWait({ prompt: req.body.message });
@@ -303,6 +305,7 @@ async function createSessionForCustomer(customerId: string) {
303305
baseUrl: config.baseUrl,
304306
apiKey: config.apiKey,
305307
},
308+
onPermissionRequest: async () => ({ kind: "approved" }),
306309
});
307310
}
308311
```
@@ -321,6 +324,7 @@ const session = await client.createSession({
321324
baseUrl: "https://api.openai.com/v1",
322325
apiKey: process.env.OPENAI_API_KEY,
323326
},
327+
onPermissionRequest: async () => ({ kind: "approved" }),
324328
});
325329

326330
// Resume later — must re-provide provider config

docs/guides/setup/github-oauth.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ const client = createClientForUser("gho_user_access_token");
134134
const session = await client.createSession({
135135
sessionId: `user-${userId}-session`,
136136
model: "gpt-4.1",
137+
onPermissionRequest: async () => ({ kind: "approved" }),
137138
});
138139

139140
const response = await session.sendAndWait({ prompt: "Hello!" });

0 commit comments

Comments
 (0)