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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 6x 48x 48x 48x 6x 48x 48x 48x 48x 48x 48x 48x 48x 48x 6x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x | import {
Entity,
Column,
ManyToOne,
OneToMany,
JoinColumn,
Index,
} from 'typeorm';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { BaseEntity } from './base.entity';
import { Session } from './session.entity';
import { ContextTemplate } from './context-template.entity';
import { AIAction } from './ai-action.entity';
import { ExecutionStrategy, MessageRole } from './enums';
/**
* A SessionInput represents a single user prompt and its associated AI response.
* Each input can generate multiple AIActions that modify files.
*
* Workflow:
* 1. POST /sessions/{sessionId}/inputs creates an input with user_prompt
* 2. Backend generates context (via template) and calls LLM
* 3. LLM response is parsed into AIActions (GET /inputs/{inputId}/actions)
* 4. User approves/discards actions, then applies or reverts
* 5. Input stores token counts and raw LLM response for history
*/
@Entity('session_inputs')
@Index(['session_id']) // Optimize EXISTS queries for non-empty sessions filter
@Index(['session_id', 'idempotency_key'], {
unique: true,
where: '"idempotency_key" IS NOT NULL',
})
export class SessionInput extends BaseEntity {
@ApiPropertyOptional({
description: 'Sequence number within session (for ordering)',
example: 1,
})
@Column({ type: 'integer', nullable: true })
sequence_number: number;
@ApiProperty({
description: 'UUID of the parent session',
format: 'uuid',
})
@Column({ type: 'uuid' })
session_id: string;
@ApiProperty({
description: 'The parent session entity',
type: () => Session,
})
@ManyToOne(() => Session, (session) => session.sessionInputs, {
nullable: false,
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'session_id' })
session: Session;
@ApiPropertyOptional({
description: 'The user prompt text sent to the LLM',
example: 'Create a new authentication module with JWT support',
})
@Column({ type: 'text', nullable: true })
user_prompt: string;
@ApiPropertyOptional({
description: 'UUID of the context template used for context generation',
format: 'uuid',
})
@Column({ type: 'uuid', nullable: true })
context_template_id: string | null;
@ApiPropertyOptional({
description: 'The context template entity used',
type: () => ContextTemplate,
})
@ManyToOne(() => ContextTemplate, (ct) => ct.sessionInputs, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn({ name: 'context_template_id' })
contextTemplate: ContextTemplate;
@ApiPropertyOptional({
description:
'Ad-hoc context definition (JSON or TEXT) for custom file/folder selection',
example: '{"files": ["src/auth.ts"], "folders": ["src/utils"]}',
})
@Column({ type: 'text', nullable: true })
ad_hoc_context_definition: string | null;
@ApiPropertyOptional({
description: 'The rendered context string sent to the LLM',
})
@Column({ type: 'text', nullable: true })
generated_context_string: string;
@ApiProperty({
description: 'How actions from this input should be processed',
enum: ExecutionStrategy,
enumName: 'ExecutionStrategy',
example: ExecutionStrategy.REVIEW_FIRST,
})
@Column({ type: 'text', nullable: true })
execution_strategy: string;
@ApiPropertyOptional({
description: 'Raw LLM response text (for debugging and history)',
})
@Column({ type: 'text', nullable: true })
raw_llm_response: string | null;
@ApiPropertyOptional({
description: 'Explanation text from the LLM response',
})
@Column({ type: 'text', nullable: true })
llm_response_explanation: string | null;
@ApiPropertyOptional({
description: 'Raw request body sent to AI Studio (for state reversion)',
})
@Column({ type: 'text', nullable: true })
raw_studio_request_body: string;
@ApiPropertyOptional({
description: 'Idempotency key to prevent duplicate submissions',
format: 'uuid',
})
@Column({ type: 'uuid', nullable: true })
idempotency_key: string | null;
@ApiPropertyOptional({
description:
'Whether this input carries context without a prompt (for context-only turns)',
example: false,
default: false,
})
@Column({ type: 'boolean', default: false })
is_context_carrier: boolean;
@ApiPropertyOptional({
description: 'AI actions generated from this input',
type: () => [AIAction],
})
@OneToMany(() => AIAction, (aiAction) => aiAction.sessionInput)
aiActions: AIAction[];
@ApiPropertyOptional({
description:
'Thinking/reasoning content from the LLM (for models that support it)',
})
@Column({ type: 'text', nullable: true })
thoughts: string | null;
@ApiPropertyOptional({
description: 'Role of this message in conversation (user or model)',
enum: MessageRole,
enumName: 'MessageRole',
})
@Column({ type: 'text', nullable: true })
role: string | null;
@ApiPropertyOptional({
description:
'External conversation ID (from synced external source like AI Studio)',
})
@Index()
@Column({ type: 'text', nullable: true })
external_conversation_id: string | null;
@ApiPropertyOptional({
description: 'External turn ID (from synced external source)',
})
@Column({ type: 'text', nullable: true })
external_turn_id: string | null;
@ApiPropertyOptional({
description: 'Number of input tokens used in this request',
example: 5000,
})
@Column({ type: 'integer', nullable: true })
input_token_count: number | null;
@ApiPropertyOptional({
description: 'Number of cached tokens used (for context caching)',
example: 3000,
})
@Column({ type: 'integer', nullable: true })
cached_token_count: number | null;
@ApiPropertyOptional({
description: 'Number of output tokens generated',
example: 800,
})
@Column({ type: 'integer', nullable: true })
output_token_count: number | null;
@ApiPropertyOptional({
description: 'Error message if LLM request failed',
})
@Column({ type: 'text', nullable: true })
error_message: string | null;
@ApiPropertyOptional({
description: 'Native tool calls from LLM response (JSON string)',
example:
'[{"name": "create_file", "arguments": {"file_path": "src/auth.ts"}}]',
})
@Column({ type: 'text', nullable: true })
tool_calls: string | null;
@ApiPropertyOptional({
description:
'Whether this input is excluded from LLM context (discarded by user)',
example: false,
default: false,
})
@Column({ type: 'boolean', default: false })
is_discarded: boolean;
}
|