Skip to content

Commit 4ee0888

Browse files
stephentoubCopilot
andauthored
Fix permission handler kinds in SDK docs and samples (#1133) (#1315)
* Fix permission handler kinds in SDK docs and samples (#1133) The SDKs distinguish two permission types that look similar but mean different things: * PermissionDecision (present tense) is what an onPermissionRequest handler returns: approve-once, approve-for-session, approve-for-location, approve-permanently, reject, user-not-available, no-result. * PermissionResult (past tense) is what shows up in permission.completed session events: approved, denied-by-rules, denied-interactively-by-user, etc. The READMEs, shared docs, and several test scenario samples were documenting and returning past-tense PermissionResult strings from onPermissionRequest handlers. That is wrong: those handlers must return PermissionDecision. This change updates every handler-return reference to use valid PermissionDecision kinds, while leaving event-payload documentation (which is legitimately past-tense) untouched. Files touched include the Node, Python, Go, and .NET READMEs, the .NET PermissionRequestResult.Kind XML doc, nodejs/docs/examples.md, the shared docs/ markdown (hooks, skills, image-input, steering-and-queueing, custom-agents, getting-started, microsoft-agent-framework), and the Python + TypeScript sample programs under test/scenarios/. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Return PermissionRequestResult in Python permission samples Python permission request handlers return PermissionRequestResult objects, not raw dictionaries. Update the docs and scenario samples that were still using dict-shaped examples so readers and scenario runs get the intended approve-once behavior instead of falling back to user-not-available. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3f9c476 commit 4ee0888

24 files changed

Lines changed: 124 additions & 103 deletions

File tree

docs/features/custom-agents.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const session = await client.createSession({
5454
prompt: "You are a code editor. Make minimal, surgical changes to files as requested.",
5555
},
5656
],
57-
onPermissionRequest: async () => ({ kind: "approved" }),
57+
onPermissionRequest: async () => ({ kind: "approve-once" }),
5858
});
5959
```
6060

@@ -71,7 +71,7 @@ client = CopilotClient()
7171
await client.start()
7272

7373
session = await client.create_session(
74-
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
74+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
7575
model="gpt-4.1",
7676
custom_agents=[
7777
{
@@ -284,7 +284,7 @@ const session = await client.createSession({
284284
skills: ["markdown-lint"],
285285
},
286286
],
287-
onPermissionRequest: async () => ({ kind: "approved" }),
287+
onPermissionRequest: async () => ({ kind: "approve-once" }),
288288
});
289289
```
290290

docs/features/hooks.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const session = await client.createSession({
5050
onPostToolUse: async (input, invocation) => { /* ... */ },
5151
// ... add only the hooks you need
5252
},
53-
onPermissionRequest: async () => ({ kind: "approved" }),
53+
onPermissionRequest: async () => ({ kind: "approve-once" }),
5454
});
5555
```
5656

@@ -61,12 +61,13 @@ const session = await client.createSession({
6161

6262
```python
6363
from copilot import CopilotClient
64+
from copilot.session import PermissionRequestResult
6465

6566
client = CopilotClient()
6667
await client.start()
6768

6869
session = await client.create_session(
69-
on_permission_request=lambda req, inv: {"kind": "approved"},
70+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
7071
hooks={
7172
"on_session_start": on_session_start,
7273
"on_pre_tool_use": on_pre_tool_use,
@@ -113,7 +114,7 @@ func main() {
113114
OnPostToolUse: onPostToolUse,
114115
},
115116
OnPermissionRequest: func(req copilot.PermissionRequest, inv copilot.PermissionInvocation) (copilot.PermissionRequestResult, error) {
116-
return copilot.PermissionRequestResult{Kind: "approved"}, nil
117+
return copilot.PermissionRequestResult{Kind: copilot.PermissionRequestResultKindApproved}, nil
117118
},
118119
})
119120
_ = session
@@ -133,7 +134,7 @@ session, err := client.CreateSession(ctx, &copilot.SessionConfig{
133134
// ... add only the hooks you need
134135
},
135136
OnPermissionRequest: func(req copilot.PermissionRequest, inv copilot.PermissionInvocation) (copilot.PermissionRequestResult, error) {
136-
return copilot.PermissionRequestResult{Kind: "approved"}, nil
137+
return copilot.PermissionRequestResult{Kind: copilot.PermissionRequestResultKindApproved}, nil
137138
},
138139
})
139140
```
@@ -251,7 +252,7 @@ const session = await client.createSession({
251252
return { permissionDecision: "allow" };
252253
},
253254
},
254-
onPermissionRequest: async () => ({ kind: "approved" }),
255+
onPermissionRequest: async () => ({ kind: "approve-once" }),
255256
});
256257
```
257258

@@ -261,6 +262,8 @@ const session = await client.createSession({
261262
<summary><strong>Python</strong></summary>
262263

263264
```python
265+
from copilot.session import PermissionRequestResult
266+
264267
READ_ONLY_TOOLS = ["read_file", "glob", "grep", "view"]
265268

266269
async def on_pre_tool_use(input_data, invocation):
@@ -273,7 +276,7 @@ async def on_pre_tool_use(input_data, invocation):
273276
return {"permissionDecision": "allow"}
274277

275278
session = await client.create_session(
276-
on_permission_request=lambda req, inv: {"kind": "approved"},
279+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
277280
hooks={"on_pre_tool_use": on_pre_tool_use},
278281
)
279282
```
@@ -463,7 +466,7 @@ const session = await client.createSession({
463466
return { permissionDecision: "allow" };
464467
},
465468
},
466-
onPermissionRequest: async () => ({ kind: "approved" }),
469+
onPermissionRequest: async () => ({ kind: "approve-once" }),
467470
});
468471
```
469472

@@ -481,7 +484,7 @@ const session = await client.createSession({
481484
return { permissionDecision: "allow" };
482485
},
483486
},
484-
onPermissionRequest: async () => ({ kind: "approved" }),
487+
onPermissionRequest: async () => ({ kind: "approve-once" }),
485488
});
486489
```
487490

@@ -563,7 +566,7 @@ const session = await client.createSession({
563566
return null;
564567
},
565568
},
566-
onPermissionRequest: async () => ({ kind: "approved" }),
569+
onPermissionRequest: async () => ({ kind: "approve-once" }),
567570
});
568571
```
569572

@@ -575,6 +578,7 @@ const session = await client.createSession({
575578
<!-- docs-validate: skip -->
576579
```python
577580
import json, aiofiles
581+
from copilot.session import PermissionRequestResult
578582

579583
audit_log = []
580584

@@ -626,7 +630,7 @@ async def on_session_end(input_data, invocation):
626630
return None
627631

628632
session = await client.create_session(
629-
on_permission_request=lambda req, inv: {"kind": "approved"},
633+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
630634
hooks={
631635
"on_session_start": on_session_start,
632636
"on_user_prompt_submitted": on_user_prompt_submitted,
@@ -661,7 +665,7 @@ const session = await client.createSession({
661665
: null;
662666
},
663667
},
664-
onPermissionRequest: async () => ({ kind: "approved" }),
668+
onPermissionRequest: async () => ({ kind: "approve-once" }),
665669
});
666670
```
667671

@@ -694,7 +698,7 @@ const session = await client.createSession({
694698
return null;
695699
},
696700
},
697-
onPermissionRequest: async () => ({ kind: "approved" }),
701+
onPermissionRequest: async () => ({ kind: "approve-once" }),
698702
});
699703
```
700704

@@ -705,6 +709,7 @@ const session = await client.createSession({
705709

706710
```python
707711
import subprocess
712+
from copilot.session import PermissionRequestResult
708713

709714
async def on_session_end(input_data, invocation):
710715
sid = invocation["session_id"][:8]
@@ -723,7 +728,7 @@ async def on_error_occurred(input_data, invocation):
723728
return None
724729

725730
session = await client.create_session(
726-
on_permission_request=lambda req, inv: {"kind": "approved"},
731+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
727732
hooks={
728733
"on_session_end": on_session_end,
729734
"on_error_occurred": on_error_occurred,
@@ -750,7 +755,7 @@ const session = await client.createSession({
750755
return null;
751756
},
752757
},
753-
onPermissionRequest: async () => ({ kind: "approved" }),
758+
onPermissionRequest: async () => ({ kind: "approve-once" }),
754759
});
755760
```
756761

@@ -774,7 +779,7 @@ const session = await client.createSession({
774779
return null;
775780
},
776781
},
777-
onPermissionRequest: async () => ({ kind: "approved" }),
782+
onPermissionRequest: async () => ({ kind: "approve-once" }),
778783
});
779784
```
780785

@@ -800,7 +805,7 @@ const session = await client.createSession({
800805
};
801806
},
802807
},
803-
onPermissionRequest: async () => ({ kind: "approved" }),
808+
onPermissionRequest: async () => ({ kind: "approve-once" }),
804809
});
805810
```
806811

@@ -826,7 +831,7 @@ const session = await client.createSession({
826831
return null;
827832
},
828833
},
829-
onPermissionRequest: async () => ({ kind: "approved" }),
834+
onPermissionRequest: async () => ({ kind: "approve-once" }),
830835
});
831836
```
832837

@@ -850,7 +855,7 @@ const session = await client.createSession({
850855
return null;
851856
},
852857
},
853-
onPermissionRequest: async () => ({ kind: "approved" }),
858+
onPermissionRequest: async () => ({ kind: "approve-once" }),
854859
});
855860
```
856861

@@ -871,7 +876,7 @@ const session = await client.createSession({
871876
};
872877
},
873878
},
874-
onPermissionRequest: async () => ({ kind: "approved" }),
879+
onPermissionRequest: async () => ({ kind: "approve-once" }),
875880
});
876881
```
877882

@@ -917,7 +922,7 @@ const session = await client.createSession({
917922
return null;
918923
},
919924
},
920-
onPermissionRequest: async () => ({ kind: "approved" }),
925+
onPermissionRequest: async () => ({ kind: "approve-once" }),
921926
});
922927
```
923928

@@ -927,6 +932,8 @@ const session = await client.createSession({
927932
<summary><strong>Python</strong></summary>
928933

929934
```python
935+
from copilot.session import PermissionRequestResult
936+
930937
session_metrics = {}
931938

932939
async def on_session_start(input_data, invocation):
@@ -956,7 +963,7 @@ async def on_session_end(input_data, invocation):
956963
return None
957964

958965
session = await client.create_session(
959-
on_permission_request=lambda req, inv: {"kind": "approved"},
966+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
960967
hooks={
961968
"on_session_start": on_session_start,
962969
"on_user_prompt_submitted": on_user_prompt_submitted,
@@ -999,7 +1006,7 @@ const session = await client.createSession({
9991006
return null;
10001007
},
10011008
},
1002-
onPermissionRequest: async () => ({ kind: "approved" }),
1009+
onPermissionRequest: async () => ({ kind: "approve-once" }),
10031010
});
10041011
```
10051012

docs/features/image-input.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ await client.start();
4848

4949
const session = await client.createSession({
5050
model: "gpt-4.1",
51-
onPermissionRequest: async () => ({ kind: "approved" }),
51+
onPermissionRequest: async () => ({ kind: "approve-once" }),
5252
});
5353

5454
await session.send({
@@ -75,7 +75,7 @@ client = CopilotClient()
7575
await client.start()
7676

7777
session = await client.create_session(
78-
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
78+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
7979
model="gpt-4.1",
8080
)
8181

@@ -263,7 +263,7 @@ await client.start();
263263

264264
const session = await client.createSession({
265265
model: "gpt-4.1",
266-
onPermissionRequest: async () => ({ kind: "approved" }),
266+
onPermissionRequest: async () => ({ kind: "approve-once" }),
267267
});
268268

269269
const base64ImageData = "..."; // your base64-encoded image
@@ -293,7 +293,7 @@ client = CopilotClient()
293293
await client.start()
294294

295295
session = await client.create_session(
296-
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
296+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
297297
model="gpt-4.1",
298298
)
299299

docs/features/skills.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const session = await client.createSession({
2929
"./skills/code-review",
3030
"./skills/documentation",
3131
],
32-
onPermissionRequest: async () => ({ kind: "approved" }),
32+
onPermissionRequest: async () => ({ kind: "approve-once" }),
3333
});
3434

3535
// Copilot now has access to skills in those directories
@@ -50,7 +50,7 @@ async def main():
5050
await client.start()
5151

5252
session = await client.create_session(
53-
on_permission_request=lambda req, inv: {"kind": "approved"},
53+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
5454
model="gpt-4.1",
5555
skill_directories=[
5656
"./skills/code-review",
@@ -375,7 +375,7 @@ const session = await client.createSession({
375375
prompt: "Focus on OWASP Top 10 vulnerabilities",
376376
skills: ["security-scan", "dependency-check"],
377377
}],
378-
onPermissionRequest: async () => ({ kind: "approved" }),
378+
onPermissionRequest: async () => ({ kind: "approve-once" }),
379379
});
380380
```
381381
> [!NOTE]
@@ -396,7 +396,7 @@ const session = await client.createSession({
396396
tools: ["*"],
397397
},
398398
},
399-
onPermissionRequest: async () => ({ kind: "approved" }),
399+
onPermissionRequest: async () => ({ kind: "approve-once" }),
400400
});
401401
```
402402

docs/features/steering-and-queueing.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ await client.start();
4848

4949
const session = await client.createSession({
5050
model: "gpt-4.1",
51-
onPermissionRequest: async () => ({ kind: "approved" }),
51+
onPermissionRequest: async () => ({ kind: "approve-once" }),
5252
});
5353

5454
// Start a long-running task
@@ -77,7 +77,7 @@ async def main():
7777
await client.start()
7878

7979
session = await client.create_session(
80-
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
80+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
8181
model="gpt-4.1",
8282
)
8383

@@ -235,7 +235,7 @@ await client.start();
235235

236236
const session = await client.createSession({
237237
model: "gpt-4.1",
238-
onPermissionRequest: async () => ({ kind: "approved" }),
238+
onPermissionRequest: async () => ({ kind: "approve-once" }),
239239
});
240240

241241
// Send an initial task
@@ -269,7 +269,7 @@ async def main():
269269
await client.start()
270270

271271
session = await client.create_session(
272-
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
272+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
273273
model="gpt-4.1",
274274
)
275275

@@ -476,7 +476,7 @@ You can use both patterns together in a single session. Steering affects the cur
476476
```typescript
477477
const session = await client.createSession({
478478
model: "gpt-4.1",
479-
onPermissionRequest: async () => ({ kind: "approved" }),
479+
onPermissionRequest: async () => ({ kind: "approve-once" }),
480480
});
481481

482482
// Start a task
@@ -502,7 +502,7 @@ await session.send({
502502

503503
```python
504504
session = await client.create_session(
505-
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
505+
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"),
506506
model="gpt-4.1",
507507
)
508508

docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ from copilot.session import PermissionRequestResult
671671

672672
client = CopilotClient()
673673

674-
session = await client.create_session(on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"))
674+
session = await client.create_session(on_permission_request=lambda req, inv: PermissionRequestResult(kind="approve-once"))
675675

676676
# Subscribe to all events
677677
unsubscribe = session.on(lambda event: print(f"Event: {event.type}"))

0 commit comments

Comments
 (0)