forked from wangziqi/gongxue-base
feat: 集成 AI 对话与只读查询工具
This commit is contained in:
56
apps/server/src/ai-chat/entities/ai-message.entity.ts
Normal file
56
apps/server/src/ai-chat/entities/ai-message.entity.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user