feat: 集成 AI 对话与只读查询工具

This commit is contained in:
2026-07-23 14:24:40 +08:00
parent 302dbe0621
commit f3b59935d6
52 changed files with 4942 additions and 4 deletions

View 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;
}