UNPKG

@wearesage/schema

Version:

A flexible schema definition and validation system for TypeScript with multi-database support

100 lines (83 loc) 2.58 kB
import { Entity, Property, Id, ManyToOne, Index, Timestamp, Auth , Labels } from '../../core/decorators'; import { RelationshipType } from '../../adapters/neo4j'; import { PostgresMetadata } from '../../adapters/metadata-layer'; import { Embeddings } from '../../adapters/embeddings'; import { TestConversation } from './TestConversation'; @Entity() @Labels(['Message']) @Auth({ permissions: ['user'] }) @PostgresMetadata({ fields: ['id', 'role', 'messageIndex', 'model', 'tokenCount', 'responseTime', 'createdAt'], tableName: 'message_metadata' }) @Embeddings({ fields: ['content', 'thinking'], model: 'nomic-embed-text:latest', provider: 'ollama', dimensions: 768, chunkSize: 512, overlap: 50, embeddingField: 'contentEmbedding', metadataFields: ['id', 'role', 'messageIndex', 'model', 'createdAt'] }) export class TestMessage { @Id() id!: string; // The conversation this message belongs to @ManyToOne({ target: () => TestConversation, inverse: 'messages', neo4j: { type: 'BELONGS_TO', direction: 'OUT' } }) @RelationshipType('BELONGS_TO') conversation!: TestConversation; // Message content @Property({ required: true }) content!: string; @Property({ required: true }) @Index() role!: 'user' | 'assistant' | 'system'; // Sender information (who sent this message) @Property() sender?: { type: 'human' | 'ai'; id: string; // userId or model name displayName?: string; // For display purposes }; // AI-specific properties @Property() thinking?: string; // AI's thinking process (for assistant messages) @Property() model?: string; // Model used for this specific message @Property() temperature?: number; // Temperature used for this message @Property() responseTime?: number; // Time taken to generate response (in milliseconds) @Property() tokenCount?: number; // Number of tokens in this message // Message ordering @Property({ required: true }) @Index() messageIndex!: number; // Order of message in conversation (0, 1, 2, ...) // Message metadata @Property() isEdited?: boolean; // Whether this message was edited after creation @Property() editHistory?: Array<{ content: string; editedAt: Date; reason?: string; }>; @Timestamp({ onCreate: true }) createdAt!: Date; @Timestamp({ onUpdate: true }) updatedAt!: Date; // Semantic embedding for content similarity search @Property() contentEmbedding?: number[]; // Constructor constructor() { this.messageIndex = 0; this.isEdited = false; } }