(self, input: Input, request: Request)
| 6 | |
| 7 | class RemoveChat(ApiHandler): |
| 8 | async def process(self, input: Input, request: Request) -> Output: |
| 9 | ctxid = input.get("context", "") |
| 10 | |
| 11 | scheduler = TaskScheduler.get() |
| 12 | scheduler.cancel_tasks_by_context(ctxid, terminate_thread=True) |
| 13 | |
| 14 | context = AgentContext.use(ctxid) |
| 15 | if context: |
| 16 | # stop processing any tasks |
| 17 | context.reset() |
| 18 | |
| 19 | AgentContext.remove(ctxid) |
| 20 | persist_chat.remove_chat(ctxid) |
| 21 | |
| 22 | await scheduler.reload() |
| 23 | |
| 24 | tasks = scheduler.get_tasks_by_context_id(ctxid) |
| 25 | for task in tasks: |
| 26 | await scheduler.remove_task_by_uuid(task.uuid) |
| 27 | |
| 28 | # Context removal affects global chat/task lists in all tabs. |
| 29 | from helpers.state_monitor_integration import mark_dirty_all |
| 30 | mark_dirty_all(reason="api.chat_remove.RemoveChat") |
| 31 | |
| 32 | return { |
| 33 | "message": "Context removed.", |
| 34 | } |
no test coverage detected