Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; @Schema({ collection: 'ai_model_definitions', timestamps: true }) export class AiModelDefinition extends Document { @Prop({ required: true, unique: true }) modelKey!: string; @Prop({ required: true }) providerKey!: string; @Prop({ required: true }) modelName!: string; @Prop({ type: [String], default: [] }) capabilities!: string[]; @Prop({ default: 0 }) costPerInputToken!: number; @Prop({ default: 0 }) costPerOutputToken!: number; @Prop({ default: 4096 }) maxContextTokens!: number; @Prop({ default: true }) isActive!: boolean; } export const AiModelDefinitionSchema = SchemaFactory.createForClass(AiModelDefinition); @Schema({ collection: 'ai_tenant_configurations', timestamps: true }) export class AiTenantConfiguration extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ default: false }) isEnabled!: boolean; @Prop({ type: [String], default: [] }) allowedModelKeys!: string[]; @Prop({ default: 10000 }) monthlyTokenLimit!: number; @Prop({ default: 0 }) usedTokensThisMonth!: number; @Prop({ default: true }) piiRedactionEnabled!: boolean; @Prop({ type: MongooseSchema.Types.Mixed, default: {} }) customSettings!: Record<string, unknown>; } export const AiTenantConfigurationSchema = SchemaFactory.createForClass( AiTenantConfiguration, ); AiTenantConfigurationSchema.index({ tenantId: 1 }, { unique: true }); @Schema({ collection: 'ai_prompt_templates', timestamps: true }) export class AiPromptTemplate extends Document { @Prop({ required: true, index: true }) key!: string; @Prop({ required: true }) name!: string; @Prop({ required: true }) description!: string; @Prop({ required: true }) capability!: string; @Prop({ required: true }) promptTemplate!: string; @Prop({ type: [String], default: [] }) requiredVariables!: string[]; @Prop({ type: [String], default: [] }) optionalVariables!: string[]; @Prop({ default: 'draft', enum: ['draft', 'published', 'archived'] }) status!: string; @Prop({ default: 1 }) version!: number; @Prop({ default: false }) requiresApproval!: boolean; @Prop({ default: false }) hasPiiRisk!: boolean; } export const AiPromptTemplateSchema = SchemaFactory.createForClass(AiPromptTemplate); AiPromptTemplateSchema.index({ key: 1, version: 1 }, { unique: true }); @Schema({ collection: 'ai_executions', timestamps: true }) export class AiExecution extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId }) userId?: MongooseSchema.Types.ObjectId; @Prop({ required: true }) promptKey!: string; @Prop({ required: true }) modelKey!: string; @Prop({ required: true }) capability!: string; @Prop({ required: true, enum: ['success', 'failed', 'timeout', 'rate_limited'], }) status!: string; @Prop({ default: 0 }) inputTokens!: number; @Prop({ default: 0 }) outputTokens!: number; @Prop({ default: 0 }) costUsd!: number; @Prop({ default: 0 }) durationMs!: number; @Prop() errorMessage?: string; } export const AiExecutionSchema = SchemaFactory.createForClass(AiExecution); |