diff --git a/application/api/user/routes.py b/application/api/user/routes.py index ae653c39..fb2caf82 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -44,6 +44,7 @@ shared_conversations_collections = db["shared_conversations"] users_collection = db["users"] user_logs_collection = db["user_logs"] user_tools_collection = db["user_tools"] +attachments_collection = db["attachments"] agents_collection.create_index( [("shared", 1)], @@ -236,13 +237,34 @@ class GetSingleConversation(Resource): ) if not conversation: return make_response(jsonify({"status": "not found"}), 404) + + # Process queries to include attachment names + queries = conversation["queries"] + for query in queries: + if "attachments" in query and query["attachments"]: + attachment_details = [] + for attachment_id in query["attachments"]: + try: + attachment = attachments_collection.find_one( + {"_id": ObjectId(attachment_id)} + ) + if attachment: + attachment_details.append({ + "id": str(attachment["_id"]), + "filename": attachment.get("filename", "Unknown file") + }) + except Exception as e: + current_app.logger.error( + f"Error retrieving attachment {attachment_id}: {e}", exc_info=True + ) + query["attachments_metadata"] = attachment_details except Exception as err: current_app.logger.error( f"Error retrieving conversation: {err}", exc_info=True ) return make_response(jsonify({"success": False}), 400) data = { - "queries": conversation["queries"], + "queries": queries, "agent_id": conversation.get("agent_id"), "is_shared_usage": conversation.get("is_shared_usage", False), "shared_token": conversation.get("shared_token", None), diff --git a/application/worker.py b/application/worker.py index 9829fde9..285b13af 100755 --- a/application/worker.py +++ b/application/worker.py @@ -475,6 +475,7 @@ def attachment_worker(self, file_info, user): "_id": doc_id, "user": user, "path": relative_path, + "filename": filename, "content": content, "token_count": token_count, "mime_type": mime_type,