mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 08:33:20 +00:00
feat: add agent timestamps and improve agent retrieval logic
This commit is contained in:
@@ -90,14 +90,23 @@ def get_agent_key(agent_id, user_id):
|
||||
if not agent_id:
|
||||
return None
|
||||
|
||||
agent = agents_collection.find_one({"_id": ObjectId(agent_id)})
|
||||
if agent is None:
|
||||
raise Exception("Agent not found", 404)
|
||||
try:
|
||||
agent = agents_collection.find_one({"_id": ObjectId(agent_id)})
|
||||
if agent is None:
|
||||
raise Exception("Agent not found", 404)
|
||||
|
||||
if agent.get("is_public") or agent.get("user") == user_id:
|
||||
return str(agent["key"])
|
||||
if agent.get("user") == user_id:
|
||||
agents_collection.update_one(
|
||||
{"_id": ObjectId(agent_id)},
|
||||
{"$set": {"lastUsedAt": datetime.datetime.now(datetime.timezone.utc)}},
|
||||
)
|
||||
return str(agent["key"])
|
||||
|
||||
raise Exception("Unauthorized access to the agent", 403)
|
||||
raise Exception("Unauthorized access to the agent", 403)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in get_agent_key: {str(e)}")
|
||||
raise
|
||||
|
||||
|
||||
def get_data_from_api_key(api_key):
|
||||
|
||||
@@ -970,6 +970,9 @@ class GetAgent(Resource):
|
||||
"tools": agent.get("tools", []),
|
||||
"agent_type": agent["agent_type"],
|
||||
"status": agent["status"],
|
||||
"createdAt": agent["createdAt"],
|
||||
"updatedAt": agent["updatedAt"],
|
||||
"lastUsedAt": agent["lastUsedAt"],
|
||||
"key": f"{agent['key'][:4]}...{agent['key'][-4:]}",
|
||||
}
|
||||
except Exception as err:
|
||||
@@ -1005,6 +1008,9 @@ class GetAgents(Resource):
|
||||
"tools": agent.get("tools", []),
|
||||
"agent_type": agent["agent_type"],
|
||||
"status": agent["status"],
|
||||
"created_at": agent["createdAt"],
|
||||
"updated_at": agent["updatedAt"],
|
||||
"last_used_at": agent["lastUsedAt"],
|
||||
"key": f"{agent['key'][:4]}...{agent['key'][-4:]}",
|
||||
}
|
||||
for agent in agents
|
||||
|
||||
Reference in New Issue
Block a user