(self, input: dict, request: Request)
| 23 | return ["POST"] |
| 24 | |
| 25 | async def process(self, input: dict, request: Request) -> dict | Response: |
| 26 | try: |
| 27 | # Get context_id from input |
| 28 | context_id = input.get("context_id") |
| 29 | |
| 30 | if not context_id: |
| 31 | return Response( |
| 32 | '{"error": "context_id is required"}', |
| 33 | status=400, |
| 34 | mimetype="application/json" |
| 35 | ) |
| 36 | |
| 37 | # Check if context exists |
| 38 | context = AgentContext.use(context_id) |
| 39 | if not context: |
| 40 | return Response( |
| 41 | '{"error": "Chat context not found"}', |
| 42 | status=404, |
| 43 | mimetype="application/json" |
| 44 | ) |
| 45 | |
| 46 | # Delete the chat context |
| 47 | AgentContext.remove(context.id) |
| 48 | remove_chat(context.id) |
| 49 | |
| 50 | # Log the deletion |
| 51 | PrintStyle( |
| 52 | background_color="#E74C3C", font_color="white", bold=True, padding=True |
| 53 | ).print(f"API Chat deleted: {context_id}") |
| 54 | |
| 55 | # Return success response |
| 56 | return { |
| 57 | "success": True, |
| 58 | "message": "Chat deleted successfully", |
| 59 | "context_id": context_id |
| 60 | } |
| 61 | |
| 62 | except Exception as e: |
| 63 | PrintStyle.error(f"API terminate chat error: {str(e)}") |
| 64 | return Response( |
| 65 | json.dumps({"error": f"Internal server error: {str(e)}"}), |
| 66 | status=500, |
| 67 | mimetype="application/json" |
| 68 | ) |
nothing calls this directly
no test coverage detected