All files / src/context-templates/dto context-template.dto.ts

96.42% Statements 27/28
100% Branches 0/0
0% Functions 0/1
96.42% Lines 27/28

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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 1436x                   6x 6x 6x   6x             6x         6x             6x         6x               6x               6x     6x               6x           6x         6x         6x         6x         6x         6x                     6x                 6x     6x       6x                 6x     6x   6x     6x    
import {
  IsNotEmpty,
  IsString,
  IsOptional,
  IsBoolean,
  IsArray,
  ValidateNested,
  IsObject,
  IsEnum,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { TemplateType } from '../../core-entities/context-template.entity';
 
export class CreateContextTemplateDto {
  @ApiProperty({
    description: 'Name of the context template',
    example: 'Full Project Context',
  })
  @IsString()
  @IsNotEmpty()
  template_name: string;
 
  @ApiProperty({ description: 'Eta template content for generating context' })
  @IsString()
  @IsNotEmpty()
  template_content: string;
 
  @ApiPropertyOptional({
    description: 'JSON string defining files/folders to include in context',
  })
  @IsOptional()
  @IsString()
  context_definition?: string;
 
  @ApiPropertyOptional({ description: 'Type of template', enum: TemplateType })
  @IsOptional()
  @IsEnum(TemplateType)
  template_type?: TemplateType;
 
  @ApiPropertyOptional({
    description: 'Whether this is a built-in template (only used by seeding)',
    example: false,
  })
  @IsOptional()
  @IsBoolean()
  is_builtin?: boolean;
 
  @ApiPropertyOptional({
    description: 'Unique key for built-in templates (only used by seeding)',
    example: 'initial-full-project-context',
  })
  @IsOptional()
  @IsString()
  builtin_key?: string;
}
 
export class UpdateContextTemplateDto {
  @ApiPropertyOptional({
    description: 'Name of the context template',
    example: 'Updated Context',
  })
  @IsOptional()
  @IsString()
  @IsNotEmpty()
  template_name?: string;
 
  @ApiPropertyOptional({ description: 'Eta template content' })
  @IsOptional()
  @IsString()
  @IsNotEmpty()
  template_content?: string;
 
  @ApiPropertyOptional({ description: 'JSON string defining files/folders' })
  @IsOptional()
  @IsString()
  context_definition?: string;
 
  @ApiPropertyOptional({ description: 'Set as default for initial prompts' })
  @IsOptional()
  @IsBoolean()
  is_default_initial?: boolean;
 
  @ApiPropertyOptional({ description: 'Set as default for follow-up prompts' })
  @IsOptional()
  @IsBoolean()
  is_default_followup?: boolean;
 
  @ApiPropertyOptional({ description: 'Set as default for condensed history' })
  @IsOptional()
  @IsBoolean()
  is_default_condensed?: boolean;
 
  @ApiPropertyOptional({ description: 'Type of template', enum: TemplateType })
  @IsOptional()
  @IsEnum(TemplateType)
  template_type?: TemplateType;
}
 
class ContextDefinitionDto {
  @ApiPropertyOptional({
    description: 'Array of file paths to include',
    example: ['src/index.ts', 'src/utils.ts'],
  })
  @IsArray()
  @IsString({ each: true })
  @IsOptional()
  files?: string[];
 
  @ApiPropertyOptional({
    description: 'Array of folder paths to include',
    example: ['src/components', 'src/hooks'],
  })
  @IsArray()
  @IsString({ each: true })
  @IsOptional()
  folders?: string[];
}
 
export class PreviewContextTemplateDto {
  @ApiProperty({ description: 'Eta template content to preview' })
  @IsString()
  @IsNotEmpty()
  template_content: string;
 
  @ApiPropertyOptional({
    description: 'Context definition object with files/folders',
  })
  @IsObject()
  @ValidateNested()
  @Type(() => ContextDefinitionDto)
  @IsOptional()
  context_definition?: ContextDefinitionDto;
}
 
export class PreviewContextTemplateResponseDto {
  @ApiProperty({ description: 'Rendered context string' })
  rendered_context: string;
 
  @ApiProperty({ description: 'Estimated token count of rendered context' })
  token_count: number;
}