mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-23 10:00:08 +08:00
feat(sessions): add CreateSessionResponse type for better type safety
Introduce CreateSessionResponse type and schema to clearly define the return type of session creation operations. This improves type safety and consistency across the codebase when handling session responses.
This commit is contained in:
parent
3b5b1986e6
commit
f5f542911f
@ -1,5 +1,6 @@
|
||||
import { loggerService } from '@logger'
|
||||
import { sessionMessageService, sessionService } from '@main/services/agents'
|
||||
import { CreateSessionResponse } from '@types'
|
||||
import { Request, Response } from 'express'
|
||||
|
||||
const logger = loggerService.withContext('ApiServerSessionsHandlers')
|
||||
@ -12,7 +13,7 @@ export const createSession = async (req: Request, res: Response): Promise<Respon
|
||||
logger.info(`Creating new session for agent: ${agentId}`)
|
||||
logger.debug('Session data:', sessionData)
|
||||
|
||||
const session = await sessionService.createSession(agentId, sessionData)
|
||||
const session = (await sessionService.createSession(agentId, sessionData)) satisfies CreateSessionResponse
|
||||
|
||||
logger.info(`Session created successfully: ${session.id}`)
|
||||
return res.status(201).json(session)
|
||||
|
||||
@ -2,6 +2,7 @@ import type {
|
||||
AgentEntity,
|
||||
AgentSessionEntity,
|
||||
CreateSessionRequest,
|
||||
CreateSessionResponse,
|
||||
GetAgentSessionResponse,
|
||||
ListOptions,
|
||||
UpdateSessionRequest
|
||||
@ -25,7 +26,7 @@ export class SessionService extends BaseService {
|
||||
await BaseService.initialize()
|
||||
}
|
||||
|
||||
async createSession(agentId: string, req: CreateSessionRequest): Promise<AgentSessionEntity> {
|
||||
async createSession(agentId: string, req: CreateSessionRequest): Promise<CreateSessionResponse> {
|
||||
this.ensureInitialized()
|
||||
|
||||
// Validate agent exists - we'll need to import AgentService for this check
|
||||
|
||||
@ -186,6 +186,10 @@ export interface CreateSessionMessageRequest {
|
||||
content: string
|
||||
}
|
||||
|
||||
export const CreateSessionResponseSchema = AgentSessionEntitySchema
|
||||
|
||||
export type CreateSessionResponse = AgentSessionEntity
|
||||
|
||||
export const AgentServerErrorSchema = z.object({
|
||||
message: z.string(),
|
||||
type: z.string(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user