refactor(sessions): update getSession and related methods to include agentId parameter

This commit is contained in:
Vaayne
2025-09-19 10:41:26 +08:00
parent 4839b91cef
commit df1d4cd62b
5 changed files with 41 additions and 45 deletions
@@ -12,7 +12,7 @@ const verifyAgentAndSession = async (agentId: string, sessionId: string) => {
throw { status: 404, code: 'agent_not_found', message: 'Agent not found' }
}
const session = await sessionService.getSession(sessionId)
const session = await sessionService.getSession(agentId, sessionId)
if (!session) {
throw { status: 404, code: 'session_not_found', message: 'Session not found' }
}
@@ -64,7 +64,7 @@ export const getSession = async (req: Request, res: Response): Promise<Response>
const { agentId, sessionId } = req.params
logger.info(`Getting session: ${sessionId} for agent: ${agentId}`)
const session = await sessionService.getSession(sessionId)
const session = await sessionService.getSession(agentId, sessionId)
if (!session) {
logger.warn(`Session not found: ${sessionId}`)
@@ -119,7 +119,7 @@ export const updateSession = async (req: Request, res: Response): Promise<Respon
logger.debug('Update data:', req.body)
// First check if session exists and belongs to agent
const existingSession = await sessionService.getSession(sessionId)
const existingSession = await sessionService.getSession(agentId, sessionId)
if (!existingSession || existingSession.agent_id !== agentId) {
logger.warn(`Session ${sessionId} not found for agent ${agentId}`)
return res.status(404).json({
@@ -133,7 +133,7 @@ export const updateSession = async (req: Request, res: Response): Promise<Respon
// For PUT, we replace the entire resource
const sessionData = { ...req.body, main_agent_id: agentId }
const session = await sessionService.updateSession(sessionId, sessionData)
const session = await sessionService.updateSession(agentId, sessionId, sessionData)
if (!session) {
logger.warn(`Session not found for update: ${sessionId}`)
@@ -167,7 +167,7 @@ export const patchSession = async (req: Request, res: Response): Promise<Respons
logger.debug('Patch data:', req.body)
// First check if session exists and belongs to agent
const existingSession = await sessionService.getSession(sessionId)
const existingSession = await sessionService.getSession(agentId, sessionId)
if (!existingSession || existingSession.agent_id !== agentId) {
logger.warn(`Session ${sessionId} not found for agent ${agentId}`)
return res.status(404).json({
@@ -180,7 +180,7 @@ export const patchSession = async (req: Request, res: Response): Promise<Respons
}
const updateSession = { ...existingSession, ...req.body }
const session = await sessionService.updateSession(sessionId, updateSession)
const session = await sessionService.updateSession(agentId, sessionId, updateSession)
if (!session) {
logger.warn(`Session not found for patch: ${sessionId}`)
@@ -213,7 +213,7 @@ export const deleteSession = async (req: Request, res: Response): Promise<Respon
logger.info(`Deleting session: ${sessionId} for agent: ${agentId}`)
// First check if session exists and belongs to agent
const existingSession = await sessionService.getSession(sessionId)
const existingSession = await sessionService.getSession(agentId, sessionId)
if (!existingSession || existingSession.agent_id !== agentId) {
logger.warn(`Session ${sessionId} not found for agent ${agentId}`)
return res.status(404).json({
@@ -225,7 +225,7 @@ export const deleteSession = async (req: Request, res: Response): Promise<Respon
})
}
const deleted = await sessionService.deleteSession(sessionId)
const deleted = await sessionService.deleteSession(agentId, sessionId)
if (!deleted) {
logger.warn(`Session not found for deletion: ${sessionId}`)
@@ -287,7 +287,7 @@ export const getSessionById = async (req: Request, res: Response): Promise<Respo
const { sessionId } = req.params
logger.info(`Getting session: ${sessionId}`)
const session = await sessionService.getSession(sessionId)
const session = await sessionService.getSessionById(sessionId)
if (!session) {
logger.warn(`Session not found: ${sessionId}`)