import { BelongsTo, Column, DataType, ForeignKey, Model, PrimaryKey, Table } from 'sequelize-typescript'; import { AiConversation } from './ai-conversation.model'; export enum RoleType { System = 'system', User = 'user', Assistant = 'assistant', } @Table({ tableName: 't_ai_messages', underscored: true, }) export class AiMessage extends Model { @PrimaryKey @Column({ type: DataType.BIGINT, autoIncrement: true, }) declare id: number; @ForeignKey(() => AiConversation) @Column({ type: DataType.STRING, allowNull: false, comment: '会话ID', }) declare conversationId: string; @Column({ type: DataType.STRING, allowNull: false, comment: '用户ID', }) declare userId: string; @Column({ type: DataType.ENUM('system', 'user', 'assistant'), allowNull: false, }) declare role: RoleType; @Column({ type: DataType.TEXT('long'), allowNull: false, }) declare content: string; @Column({ type: DataType.JSON, allowNull: true, comment: '扩展元数据,如token用量、模型名等', }) declare metadata: Record | null; @Column({ type: DataType.DATE, defaultValue: DataType.NOW, }) declare createdAt: Date; @Column({ type: DataType.DATE, defaultValue: DataType.NOW, }) declare updatedAt: Date; @BelongsTo(() => AiConversation) declare conversation?: AiConversation; }