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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 6x 48x 48x 48x 48x 48x 6x 48x 48x 6x 48x 48x 6x 48x 48x 48x 48x 48x 6x 48x 48x 6x 48x 6x 48x 6x 48x 48x | import { Entity, Column, ManyToOne, OneToMany, JoinColumn } from 'typeorm';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { BaseEntity } from './base.entity';
import { Project } from './project.entity';
import { ContextTemplate } from './context-template.entity';
import { SessionInput } from './session-input.entity';
import { SystemPrompt } from './system-prompt.entity';
import { SubAgent } from '../sub-agents/sub-agent.entity';
import { SessionStatus, ReasoningEffort } from './enums';
/**
* A Session represents a conversation with the AI for a specific project.
* It tracks all inputs (prompts), AI responses, and resulting file actions.
*
* Workflow:
* 1. Create session (optionally link to Project)
* 2. Set as active via POST /sessions/{id}/set-active
* 3. Create inputs via POST /sessions/{sessionId}/inputs
* 4. Each input generates AIActions that modify files
* 5. Complete or abort session when done
*/
@Entity('sessions')
export class Session extends BaseEntity {
@ApiPropertyOptional({
description: 'UUID of the associated project',
format: 'uuid',
example: '550e8400-e29b-41d4-a716-446655440001',
})
@Column({ type: 'uuid', nullable: true })
project_id: string | null;
@ApiPropertyOptional({
description: 'The project this session belongs to',
type: () => Project,
})
@ManyToOne(() => Project, (project) => project.sessions, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn({ name: 'project_id' })
project: Project;
@ApiPropertyOptional({
description: 'Human-readable title for the session',
example: 'Refactor authentication module',
maxLength: 255,
})
@Column({ type: 'text', nullable: true })
session_title: string;
@ApiPropertyOptional({
description: 'Timestamp when the session ended',
type: 'string',
format: 'date-time',
})
@Column({ type: 'datetime', nullable: true })
end_time: Date;
@ApiProperty({
description: 'Current status of the session',
enum: SessionStatus,
example: SessionStatus.ACTIVE,
enumName: 'SessionStatus',
})
@Column({ type: 'text' })
status: string;
@ApiPropertyOptional({
description: 'UUID of the system prompt configuration used',
format: 'uuid',
})
@Column({ type: 'uuid', nullable: true })
system_prompt_id: string;
@ApiPropertyOptional({
description: 'The system prompt entity used for this session',
type: () => SystemPrompt,
})
@ManyToOne(() => SystemPrompt, (sp) => sp.sessions, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn({ name: 'system_prompt_id' })
systemPrompt: SystemPrompt;
@ApiPropertyOptional({
description: 'UUID of default context template for initial prompts',
format: 'uuid',
})
@Column({ type: 'uuid', nullable: true })
default_initial_context_template_id: string;
@ApiPropertyOptional({
description: 'Default context template for initial prompts in this session',
type: () => ContextTemplate,
})
@ManyToOne(() => ContextTemplate, (ct) => ct.sessionsAsInitialDefault, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn({ name: 'default_initial_context_template_id' })
defaultInitialContextTemplate: ContextTemplate;
@ApiPropertyOptional({
description: 'UUID of default context template for follow-up prompts',
format: 'uuid',
})
@Column({ type: 'uuid', nullable: true })
default_followup_context_template_id: string;
@ApiPropertyOptional({
description:
'Default context template for follow-up prompts in this session',
type: () => ContextTemplate,
})
@ManyToOne(() => ContextTemplate, (ct) => ct.sessionsAsFollowupDefault, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn({ name: 'default_followup_context_template_id' })
defaultFollowupContextTemplate: ContextTemplate;
@ApiPropertyOptional({
description: 'External URL link (e.g., AI Studio or Claude chat URL)',
example: 'https://aistudio.google.com/chat/abc123',
})
@Column({ type: 'text', nullable: true })
url: string | null;
@ApiPropertyOptional({
description: 'Model identifier used for this session',
example: 'gemini-2.0-flash',
})
@Column({ type: 'text', nullable: true })
model_id: string | null;
@ApiPropertyOptional({
description: 'Reasoning effort level for the model',
enum: ReasoningEffort,
enumName: 'ReasoningEffort',
example: ReasoningEffort.MEDIUM,
})
@Column({ type: 'text', nullable: true })
reasoning_effort: ReasoningEffort | null;
@ApiPropertyOptional({
description: 'UUID of the sub-agent assigned to this session',
format: 'uuid',
})
@Column({ type: 'uuid', nullable: true })
sub_agent_id: string | null;
@ApiPropertyOptional({
description: 'The sub-agent entity assigned to this session',
type: () => SubAgent,
})
@ManyToOne(() => SubAgent, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn({ name: 'sub_agent_id' })
subAgent: SubAgent;
@ApiPropertyOptional({
description: 'UUID of parent session (for follow-up/spawned sessions)',
format: 'uuid',
})
@Column({ type: 'uuid', nullable: true })
parent_session_id: string | null;
@ApiPropertyOptional({
description: 'The parent session this was spawned from',
type: () => Session,
})
@ManyToOne(() => Session, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn({ name: 'parent_session_id' })
parentSession: Session;
@ApiPropertyOptional({
description: 'All input prompts in this session',
type: () => [SessionInput],
})
@OneToMany(() => SessionInput, (sessionInput) => sessionInput.session)
sessionInputs: SessionInput[];
@ApiPropertyOptional({
description: 'Child sessions spawned from this session',
type: () => [Session],
})
@OneToMany(() => Session, 'parent_session_id')
childSessions: Session[];
@ApiPropertyOptional({
description: 'Count of inputs in this session (computed field)',
example: 5,
})
sessionInputCount: number;
}
|