Fix ImportError: SessionEventType not exported from copilot public API#1093
Merged
aaronpowell merged 2 commits intostagedfrom Mar 19, 2026
Merged
Fix ImportError: SessionEventType not exported from copilot public API#1093aaronpowell merged 2 commits intostagedfrom
aaronpowell merged 2 commits intostagedfrom
Conversation
…ring comparisons Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/awesome-copilot/sessions/0c514b95-5157-4aa9-8590-cbf3fd337472
Copilot
AI
changed the title
[WIP] Fix snippet example ImportError in managing local files
Fix ImportError: SessionEventType not exported from copilot public API
Mar 19, 2026
aaronpowell
approved these changes
Mar 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Python cookbook recipes that currently raise ImportError by importing SessionEventType from the top-level copilot module, switching the event handling logic to use string comparisons via event.type.value instead.
Changes:
- Remove
SessionEventTypeimports from 3 runnable Python recipes and update event-type checks toevent.type.value == "...". - Update the corresponding 3 markdown recipe docs so inline code snippets match the runnable recipes.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| cookbook/copilot-sdk/python/recipe/pr_visualization.py | Drops SessionEventType import and compares event.type.value against event name strings. |
| cookbook/copilot-sdk/python/recipe/managing_local_files.py | Same fix: remove SessionEventType import; switch enum comparisons to event.type.value strings. |
| cookbook/copilot-sdk/python/recipe/accessibility_report.py | Same fix for streaming delta events; keeps event handling consistent with other recipes. |
| cookbook/copilot-sdk/python/pr-visualization.md | Syncs doc snippet imports and event checks with the updated runnable recipe. |
| cookbook/copilot-sdk/python/managing-local-files.md | Syncs doc snippet imports and event checks with the updated runnable recipe. |
| cookbook/copilot-sdk/python/accessibility-report.md | Syncs doc snippet imports and event checks with the updated runnable recipe. |
Comments suppressed due to low confidence (1)
cookbook/copilot-sdk/python/accessibility-report.md:88
- This snippet now uses
event.type.value == "assistant.message_delta", but the later "How it works" section still says it usesASSISTANT_MESSAGE_DELTAevents. Please update that narrative to match the new string-based event type approach (e.g., refer toassistant.message_delta/event.type.value).
if event.type.value == "assistant.message_delta":
print(event.data.delta_content or "", end="", flush=True)
elif event.type.value == "session.idle":
done.set()
elif event.type.value == "session.error":
print(f"\nError: {event.data.message}")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SessionEventTypeis not exported from the top-levelcopilotmodule (it lives in the internalcopilot.generated.session_eventsmodule), causingImportErrorwhen running any of the affected Python cookbook recipes.Changes
managing_local_files.py,accessibility_report.py,pr_visualization.py): RemoveSessionEventTypefrom imports; replace enum comparisons withevent.type.value == "..."string comparisons — the pattern used in the official SDK READMEmanaging-local-files.md,accessibility-report.md,pr-visualization.md): Sync inline code snippets to match the fixed recipesBefore:
After:
Pull Request Checklist
npm startand verified thatREADME.mdis up to date.Description
SessionEventTypeis not part of the publiccopilotpackage API, causingImportErrorfor all Python cookbook recipes that import it. Replace withevent.type.valuestring comparisons, consistent with the SDK's own documentation.Type of Contribution
Additional Notes
SessionEventTypeexists atcopilot.generated.session_events.SessionEventTypebut is intentionally not re-exported at the package level. The SDK README consistently usesevent.type.value == "..."string comparisons, so this fix aligns the cookbook with the documented pattern rather than reaching into internal modules.By submitting this pull request, I confirm that my contribution abides by the Code of Conduct and will be licensed under the MIT License.
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.