()
| 13 | |
| 14 | |
| 15 | async def main(): |
| 16 | client = CopilotClient() |
| 17 | await client.start() |
| 18 | session = await client.create_session(on_permission_request=PermissionHandler.approve_all) |
| 19 | |
| 20 | def on_event(event): |
| 21 | output = None |
| 22 | match event.data: |
| 23 | case AssistantReasoningData() as data: |
| 24 | output = f"[reasoning: {data.content}]" |
| 25 | case ToolExecutionStartData() as data: |
| 26 | output = f"[tool: {data.tool_name}]" |
| 27 | if output: |
| 28 | print(f"{BLUE}{output}{RESET}") |
| 29 | |
| 30 | session.on(on_event) |
| 31 | |
| 32 | print("Chat with Copilot (Ctrl+C to exit)\n") |
| 33 | |
| 34 | while True: |
| 35 | user_input = input("You: ").strip() |
| 36 | if not user_input: |
| 37 | continue |
| 38 | print() |
| 39 | |
| 40 | reply = await session.send_and_wait(user_input) |
| 41 | assistant_output = None |
| 42 | if reply: |
| 43 | match reply.data: |
| 44 | case AssistantMessageData() as data: |
| 45 | assistant_output = data.content |
| 46 | print(f"\nAssistant: {assistant_output}\n") |
| 47 | |
| 48 | |
| 49 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…