feat(client): 新增会话管理与消息落库能力

补齐客户端会话生命周期接口(创建、列表、消息分页、改名、删除),并在流式 chat 中强制绑定 sessionId 与落库消息,确保会话标题和历史可追踪,同时统一 Swagger 文档为 DTO 驱动以减少重复维护。

Made-with: Cursor
This commit is contained in:
2026-04-22 23:32:10 +08:00
parent bc13417efd
commit 32303d099a
16 changed files with 833 additions and 146 deletions

View File

@@ -3,24 +3,38 @@ import { Type } from 'class-transformer';
import { IsArray, IsIn, IsOptional, IsString, ValidateNested } from 'class-validator';
import { StreamChatRequest } from '@shared/ai-gateway/types/chat.types';
class ChatMessageDto {
@ApiProperty({ enum: ['system', 'user', 'assistant'] })
export class ChatMessageDto {
@ApiProperty({
type: String,
enum: ['system', 'user', 'assistant'],
description: '消息角色',
example: 'user',
})
@IsString()
@IsIn(['system', 'user', 'assistant'])
role!: 'system' | 'user' | 'assistant';
@ApiProperty({ description: '消息内容', example: '你是谁' })
@ApiProperty({ type: String, description: '消息内容', example: '你是谁' })
@IsString()
content!: string;
}
export class StreamChatBodyDto implements StreamChatRequest {
@ApiPropertyOptional({ description: '模型名', example: 'qwen-plus' })
@ApiPropertyOptional({ type: String, description: '模型名', example: 'qwen-plus' })
@IsOptional()
@IsString()
model?: string;
@ApiProperty({
type: String,
description: '会话 ID数字字符串需先调用创建会话接口获取',
example: '1',
})
@IsString()
sessionId!: string;
@ApiPropertyOptional({
type: String,
description: '指定平台,不传或 auto 由路由自动选择',
enum: ['auto', 'qwen', 'deepseek', 'volc'],
example: 'qwen',
@@ -29,7 +43,11 @@ export class StreamChatBodyDto implements StreamChatRequest {
@IsString()
platform?: string;
@ApiProperty({ type: [ChatMessageDto] })
@ApiProperty({
type: () => ChatMessageDto,
isArray: true,
description: '聊天消息列表(至少一条用户消息)',
})
@IsArray()
@ValidateNested({ each: true })
@Type(() => ChatMessageDto)