Skip to content

Commit 84372b7

Browse files
brettcannonCopilot
andcommitted
Address PR review comments for create_session refactor
- Add validation for on_permission_request in create_session to fail fast when handler is missing/invalid - Fix lambda signatures to accept two args (request, invocation) in test scenario and docs - Fix permissionDecision key to use camelCase in pre_tool_use hook Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8283fb9 commit 84372b7

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

docs/guides/skills.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def main():
4949
await client.start()
5050

5151
session = await client.create_session(
52-
lambda req: {"kind": "approved"},
52+
lambda req, inv: {"kind": "approved"},
5353
"gpt-4.1",
5454
skill_directories=[
5555
"./skills/code-review",

python/copilot/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,12 @@ async def create_session(
493493
... streaming=True,
494494
... )
495495
"""
496+
if not on_permission_request or not callable(on_permission_request):
497+
raise ValueError(
498+
"A valid on_permission_request handler is required. "
499+
"Use PermissionHandler.approve_all or provide a custom handler."
500+
)
501+
496502
if not self._client:
497503
if self.options["auto_start"]:
498504
await self.start()

test/scenarios/tools/skills/python/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ async def main():
1515
skills_dir = str(Path(__file__).resolve().parent.parent / "sample-skills")
1616

1717
session = await client.create_session(
18-
lambda _: {"kind": "approved"},
18+
lambda _, __: {"kind": "approved"},
1919
"claude-haiku-4.5",
2020
skill_directories=[skills_dir],
2121
hooks={
22-
"on_pre_tool_use": lambda _: {"permission_decision": "allow"},
22+
"on_pre_tool_use": lambda _, __: {"permissionDecision": "allow"},
2323
},
2424
)
2525

0 commit comments

Comments
 (0)