All files / src/core-entities system-prompt.entity.ts

95% Statements 19/20
100% Branches 0/0
66.66% Functions 2/3
94.11% Lines 16/17

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 8948x 48x 48x 48x                     48x           48x             48x               48x             48x             48x               48x             48x               48x             48x           6x 48x    
import { Entity, Column, OneToMany } from 'typeorm';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { BaseEntity } from './base.entity';
import { Session } from './session.entity';
 
/**
 * SystemPrompt defines the AI's behavior and instructions.
 * It contains the master prompt template that gets rendered with tool definitions.
 *
 * Each session can use a different system prompt.
 * System prompts can be pushed to external AI interfaces like AI Studio.
 * Tool definitions are injected into the prompt content before sending to LLM.
 */
@Entity('system_prompts')
export class SystemPrompt extends BaseEntity {
  @ApiProperty({
    description: 'Human-readable name for this system prompt',
    example: 'Default Assistant',
  })
  @Column({ type: 'text' })
  prompt_name: string;
 
  @ApiProperty({
    description:
      'Prompt content (Eta template syntax supported). Tool definitions are injected when rendered.',
  })
  @Column({ type: 'text' })
  prompt_content: string;
 
  @ApiProperty({
    description: 'Whether this is the default system prompt for new sessions',
    example: true,
    default: false,
  })
  @Column({ type: 'boolean', default: false })
  is_default: boolean;
 
  @ApiPropertyOptional({
    description: 'URL link to external AI interface (e.g., AI Studio)',
    example: 'https://aistudio.google.com',
  })
  @Column({ type: 'text', nullable: true })
  url: string;
 
  @ApiPropertyOptional({
    description: 'Enabled tools: "all" or JSON array of tool names',
    example: 'all',
  })
  @Column({ type: 'text', nullable: true })
  enabledTools: string | null;
 
  @ApiPropertyOptional({
    description:
      'Enabled MCP tools: "all" or JSON array of serverName__toolName identifiers. "all" inherits globally active MCP tools.',
    example: 'all',
  })
  @Column({ type: 'text', nullable: true })
  enabledMcpTools: string | null;
 
  @ApiPropertyOptional({
    description: 'Token limit for follow-up context generation',
    example: 8000,
  })
  @Column({ type: 'integer', nullable: true })
  followup_token_limit: number | null;
 
  @ApiProperty({
    description: 'Whether this is a built-in seed prompt (immutable)',
    example: false,
    default: false,
  })
  @Column({ type: 'boolean', default: false })
  is_builtin: boolean;
 
  @ApiPropertyOptional({
    description: 'Unique key for built-in prompts (used for version updates)',
    example: 'master-agent',
  })
  @Column({ type: 'text', nullable: true, unique: true })
  builtin_key: string | null;
 
  @ApiPropertyOptional({
    description: 'Sessions using this system prompt',
    type: () => [Session],
  })
  @OneToMany(() => Session, (session) => session.systemPrompt)
  sessions: Session[];
}