补齐客户端会话生命周期接口(创建、列表、消息分页、改名、删除),并在流式 chat 中强制绑定 sessionId 与落库消息,确保会话标题和历史可追踪,同时统一 Swagger 文档为 DTO 驱动以减少重复维护。 Made-with: Cursor
81 lines
1.9 KiB
TypeScript
81 lines
1.9 KiB
TypeScript
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||
|
||
export class ChatSessionRowDto {
|
||
@ApiProperty({ type: String, example: '1', description: '会话 ID(数字字符串)' })
|
||
id!: string;
|
||
|
||
@ApiProperty({ type: String, example: '1', description: '用户 ID(数字字符串)' })
|
||
userId!: string;
|
||
|
||
@ApiProperty({
|
||
type: String,
|
||
description: '标题(可能为空字符串)',
|
||
example: '你好',
|
||
})
|
||
title!: string;
|
||
|
||
@ApiProperty({ type: String, description: '创建时间 ISO8601' })
|
||
createdAt!: string;
|
||
|
||
@ApiProperty({ type: String, description: '更新时间 ISO8601' })
|
||
updatedAt!: string;
|
||
}
|
||
|
||
export class ChatSessionListResponseDto {
|
||
@ApiProperty({ type: () => ChatSessionRowDto, isArray: true })
|
||
items!: ChatSessionRowDto[];
|
||
|
||
@ApiProperty({ type: Number })
|
||
total!: number;
|
||
|
||
@ApiProperty({ type: Number })
|
||
limit!: number;
|
||
|
||
@ApiProperty({ type: Number })
|
||
offset!: number;
|
||
}
|
||
|
||
export class ChatMessageRowDto {
|
||
@ApiProperty({ type: String, example: '1', description: '消息 ID(数字字符串)' })
|
||
id!: string;
|
||
|
||
@ApiProperty({ type: String, example: 'user' })
|
||
role!: string;
|
||
|
||
@ApiProperty({ type: String })
|
||
content!: string;
|
||
|
||
@ApiProperty({
|
||
type: Number,
|
||
description: 'completion token 数(用户消息为 0)',
|
||
})
|
||
tokenCount!: number;
|
||
|
||
@ApiPropertyOptional({
|
||
type: String,
|
||
nullable: true,
|
||
description: '大模型渠道(用户消息一般为 null)',
|
||
})
|
||
provider?: string | null;
|
||
|
||
@ApiProperty({ type: String, description: '创建时间 ISO8601' })
|
||
createdAt!: string;
|
||
}
|
||
|
||
export class ChatMessageListResponseDto {
|
||
@ApiProperty({ type: String, example: '1' })
|
||
sessionId!: string;
|
||
|
||
@ApiProperty({ type: () => ChatMessageRowDto, isArray: true })
|
||
items!: ChatMessageRowDto[];
|
||
|
||
@ApiProperty({ type: Number })
|
||
total!: number;
|
||
|
||
@ApiProperty({ type: Number })
|
||
limit!: number;
|
||
|
||
@ApiProperty({ type: Number })
|
||
offset!: number;
|
||
}
|