Handle /compact command - compact conversation context. Args: args: Command arguments context: Command context Returns: LocalCommandResult
(args: str, context: CommandContext)
| 991 | |
| 992 | |
| 993 | def compact_command_call(args: str, context: CommandContext) -> LocalCommandResult: |
| 994 | """ |
| 995 | Handle /compact command - compact conversation context. |
| 996 | |
| 997 | Args: |
| 998 | args: Command arguments |
| 999 | context: Command context |
| 1000 | |
| 1001 | Returns: |
| 1002 | LocalCommandResult |
| 1003 | """ |
| 1004 | # Run the async version in a new event loop |
| 1005 | try: |
| 1006 | loop = asyncio.get_running_loop() |
| 1007 | # If we're already in an async context, we can't use asyncio.run |
| 1008 | # Fall back to sync path |
| 1009 | return _sync_compact_fallback(context) |
| 1010 | except RuntimeError: |
| 1011 | # No running event loop — safe to use asyncio.run |
| 1012 | try: |
| 1013 | return asyncio.run(_compact_async(args, context)) |
| 1014 | except Exception as e: |
| 1015 | import traceback |
| 1016 | traceback.print_exc() |
| 1017 | return _sync_compact_fallback(context) |
| 1018 | |
| 1019 | |
| 1020 | def _sync_compact_fallback(context: CommandContext) -> LocalCommandResult: |
no test coverage detected