mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
✨ feat(sessions): include session messages in session retrieval response
This commit is contained in:
parent
ca8ac9911e
commit
b6187ad637
@ -1,6 +1,6 @@
|
|||||||
import { Request, Response } from 'express'
|
import { Request, Response } from 'express'
|
||||||
|
|
||||||
import { sessionService } from '../../../../services/agents'
|
import { sessionMessageService, sessionService } from '../../../../services/agents'
|
||||||
import { loggerService } from '../../../../services/LoggerService'
|
import { loggerService } from '../../../../services/LoggerService'
|
||||||
|
|
||||||
const logger = loggerService.withContext('ApiServerSessionsHandlers')
|
const logger = loggerService.withContext('ApiServerSessionsHandlers')
|
||||||
@ -89,8 +89,18 @@ export const getSession = async (req: Request, res: Response): Promise<Response>
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`Session retrieved successfully: ${sessionId}`)
|
// Fetch session messages
|
||||||
return res.json(session)
|
logger.info(`Fetching messages for session: ${sessionId}`)
|
||||||
|
const { messages } = await sessionMessageService.listSessionMessages(sessionId)
|
||||||
|
|
||||||
|
// Add messages to session
|
||||||
|
const sessionWithMessages = {
|
||||||
|
...session,
|
||||||
|
messages: messages
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(`Session retrieved successfully: ${sessionId} with ${messages.length} messages`)
|
||||||
|
return res.json(sessionWithMessages)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
logger.error('Error getting session:', error)
|
logger.error('Error getting session:', error)
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
|
|||||||
@ -61,6 +61,7 @@ export interface AgentSessionEntity extends AgentConfiguration {
|
|||||||
user_goal?: string // Initial user goal for the session
|
user_goal?: string // Initial user goal for the session
|
||||||
status: SessionStatus
|
status: SessionStatus
|
||||||
external_session_id?: string // Agent session for external agent management/tracking
|
external_session_id?: string // Agent session for external agent management/tracking
|
||||||
|
messages?: SessionMessageEntity[] // Hierarchical session messages
|
||||||
created_at: string
|
created_at: string
|
||||||
updated_at: string
|
updated_at: string
|
||||||
}
|
}
|
||||||
@ -72,7 +73,7 @@ export interface SessionMessageEntity {
|
|||||||
parent_id?: number // For tree structure (e.g., tool calls under an action)
|
parent_id?: number // For tree structure (e.g., tool calls under an action)
|
||||||
role: SessionMessageRole // 'user', 'agent', 'system', 'tool'
|
role: SessionMessageRole // 'user', 'agent', 'system', 'tool'
|
||||||
type: SessionMessageType // Type of log entry
|
type: SessionMessageType // Type of log entry
|
||||||
content: Record<string, any> // JSON structured data
|
content: string | Record<string, any> // JSON structured data
|
||||||
metadata?: Record<string, any> // Additional metadata (optional)
|
metadata?: Record<string, any> // Additional metadata (optional)
|
||||||
created_at: string // ISO timestamp
|
created_at: string // ISO timestamp
|
||||||
updated_at: string // ISO timestamp
|
updated_at: string // ISO timestamp
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user