chat-message.entity.ts 919 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {
  2. Entity,
  3. PrimaryGeneratedColumn,
  4. Column,
  5. CreateDateColumn,
  6. ManyToOne,
  7. JoinColumn,
  8. } from 'typeorm';
  9. import { SearchHistory } from './search-history.entity';
  10. import { Tenant } from '../tenant/tenant.entity';
  11. @Entity('chat_messages')
  12. export class ChatMessage {
  13. @PrimaryGeneratedColumn('uuid')
  14. id: string;
  15. @Column({ name: 'search_history_id' })
  16. searchHistoryId: string;
  17. @Column({ name: 'tenant_id', nullable: true, type: 'text' })
  18. tenantId: string;
  19. @Column()
  20. role: 'user' | 'assistant';
  21. @Column('text')
  22. content: string;
  23. @Column({ nullable: true })
  24. sources?: string; // JSON string
  25. @CreateDateColumn({ name: 'created_at' })
  26. createdAt: Date;
  27. @ManyToOne(() => SearchHistory, (history) => history.messages)
  28. @JoinColumn({ name: 'search_history_id' })
  29. searchHistory: SearchHistory;
  30. @ManyToOne(() => Tenant)
  31. @JoinColumn({ name: 'tenant_id' })
  32. tenant: Tenant;
  33. }