Files
awesome-copilot/cookbook/copilot-sdk/python/recipe/managing_local_files.py
Copilot 6fbbc5204e Fix ImportError: SessionEventType not exported from copilot public API (#1093)
* Initial plan

* Fix ImportError: remove SessionEventType from copilot imports, use string 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

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
2026-03-20 10:51:21 +11:00

55 lines
1.5 KiB
Python

#!/usr/bin/env python3
import asyncio
import os
from copilot import (
CopilotClient, SessionConfig, MessageOptions,
SessionEvent,
)
async def main():
# Create and start client
client = CopilotClient()
await client.start()
# Create session
session = await client.create_session(SessionConfig(model="gpt-5"))
done = asyncio.Event()
# Event handler
def handle_event(event: SessionEvent):
if event.type.value == "assistant.message":
print(f"\nCopilot: {event.data.content}")
elif event.type.value == "tool.execution_start":
print(f" → Running: {event.data.tool_name}")
elif event.type.value == "tool.execution_complete":
print(f" ✓ Completed: {event.data.tool_call_id}")
elif event.type.value == "session.idle":
done.set()
session.on(handle_event)
# Ask Copilot to organize files
# Change this to your target folder
target_folder = os.path.expanduser("~/Downloads")
await session.send(MessageOptions(prompt=f"""
Analyze the files in "{target_folder}" and organize them into subfolders.
1. First, list all files and their metadata
2. Preview grouping by file extension
3. Create appropriate subfolders (e.g., "images", "documents", "videos")
4. Move each file to its appropriate subfolder
Please confirm before moving any files.
"""))
await done.wait()
await session.destroy()
await client.stop()
if __name__ == "__main__":
asyncio.run(main())