MCPcopy
hub / github.com/PromtEngineer/localGPT / handle_rename_session

Method handle_rename_session

backend/server.py:1025–1057  ·  view source on GitHub ↗

Rename an existing session title

(self, session_id: str)

Source from the content-addressed store, hash-verified

1023 self.send_json_response({'error': str(e)}, status_code=500)
1024
1025 def handle_rename_session(self, session_id: str):
1026 """Rename an existing session title"""
1027 try:
1028 session = db.get_session(session_id)
1029 if not session:
1030 self.send_json_response({"error": "Session not found"}, status_code=404)
1031 return
1032
1033 content_length = int(self.headers.get('Content-Length', 0))
1034 if content_length == 0:
1035 self.send_json_response({"error": "Request body required"}, status_code=400)
1036 return
1037
1038 post_data = self.rfile.read(content_length)
1039 data = json.loads(post_data.decode('utf-8'))
1040 new_title: str = data.get('title', '').strip()
1041
1042 if not new_title:
1043 self.send_json_response({"error": "Title cannot be empty"}, status_code=400)
1044 return
1045
1046 db.update_session_title(session_id, new_title)
1047 updated_session = db.get_session(session_id)
1048
1049 self.send_json_response({
1050 "message": "Session renamed successfully",
1051 "session": updated_session
1052 })
1053
1054 except json.JSONDecodeError:
1055 self.send_json_response({"error": "Invalid JSON"}, status_code=400)
1056 except Exception as e:
1057 self.send_json_response({"error": f"Failed to rename session: {str(e)}"}, status_code=500)
1058
1059 def send_json_response(self, data, status_code: int = 200):
1060 """Send a JSON (UTF-8) response with CORS headers. Safe against client disconnects."""

Callers 1

do_POSTMethod · 0.95

Calls 3

send_json_responseMethod · 0.95
get_sessionMethod · 0.80
update_session_titleMethod · 0.80

Tested by

no test coverage detected