forked from wangziqi/gongxue-base
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
Index,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
PrimaryGeneratedColumn,
|
|
UpdateDateColumn,
|
|
} from 'typeorm';
|
|
import { AiConversation } from './ai-conversation.entity';
|
|
import { AiToolRun } from './ai-tool-run.entity';
|
|
|
|
export type AiMessageRole = 'user' | 'assistant';
|
|
export type AiMessageStatus = 'pending' | 'completed' | 'failed' | 'cancelled';
|
|
|
|
@Entity('ai_messages')
|
|
@Index('idx_ai_messages_conversation_created', ['conversationId', 'createdAt'])
|
|
export class AiMessage {
|
|
@PrimaryGeneratedColumn()
|
|
id: number;
|
|
|
|
@Column({ name: 'conversation_id', type: 'integer' })
|
|
conversationId: number;
|
|
|
|
@ManyToOne(() => AiConversation, (conversation) => conversation.messages, {
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'conversation_id' })
|
|
conversation: AiConversation;
|
|
|
|
@Column({ type: 'varchar', length: 20 })
|
|
role: AiMessageRole;
|
|
|
|
@Column({ type: 'text', default: '' })
|
|
content: string;
|
|
|
|
@Column({ name: 'reasoning_content', type: 'text', nullable: true })
|
|
reasoningContent: string | null;
|
|
|
|
@Column({ type: 'varchar', length: 20, default: 'completed' })
|
|
status: AiMessageStatus;
|
|
|
|
@Column({ name: 'error_code', type: 'varchar', length: 50, nullable: true })
|
|
errorCode: string | null;
|
|
|
|
@OneToMany(() => AiToolRun, (run) => run.message)
|
|
toolRuns: AiToolRun[];
|
|
|
|
@CreateDateColumn({ name: 'created_at', type: 'datetime' })
|
|
createdAt: Date;
|
|
|
|
@UpdateDateColumn({ name: 'updated_at', type: 'datetime' })
|
|
updatedAt: Date;
|
|
}
|