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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 18x 7x 7x 7x 7x 7x 2x 2x 7x 7x 7x 7x 7x 7x 7x 7x 2x 2x 7x 2x 2x 7x 3x 3x 3x 7x 2x 2x 7x 7x 3x 7x 7x 7x | import {
Controller,
Get,
Post,
Body,
Param,
Put,
Delete,
ParseUUIDPipe,
HttpCode,
HttpStatus,
Patch,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger';
import { SystemPromptsService } from './system-prompts.service';
import {
CreateSystemPromptDto,
PreviewSystemPromptDto,
PreviewSystemPromptResponseDto,
UpdateSystemPromptDto,
} from './dto/system-prompt.dto';
import { SetEnabledToolsDto } from './dto/set-enabled-tools.dto';
import { ToggleToolDto } from './dto/toggle-tool.dto';
import { SetEnabledMcpToolsDto } from './dto/set-enabled-mcp-tools.dto';
import { ToggleMcpToolDto } from './dto/toggle-mcp-tool.dto';
import { SystemPrompt } from '../core-entities';
@ApiTags('system-prompts')
@Controller('system-prompts')
export class SystemPromptsController {
constructor(private readonly systemPromptsService: SystemPromptsService) {}
@Post()
@ApiOperation({ summary: 'Create a new system prompt' })
@ApiResponse({
status: 201,
description: 'System prompt created',
type: SystemPrompt,
})
async create(
@Body() createSystemPromptDto: CreateSystemPromptDto,
): Promise<SystemPrompt> {
return this.systemPromptsService.create(createSystemPromptDto);
}
@Post('preview')
@HttpCode(HttpStatus.OK)
@ApiOperation({
summary: 'Preview rendered system prompt (inject tool definitions)',
})
@ApiResponse({
status: 200,
description: 'Rendered prompt',
type: PreviewSystemPromptResponseDto,
})
async preview(
@Body() previewDto: PreviewSystemPromptDto,
): Promise<PreviewSystemPromptResponseDto> {
return this.systemPromptsService.preview(previewDto);
}
@Get('tools')
@ApiOperation({ summary: 'Get names of tools enabled for current session' })
@ApiResponse({ status: 200, description: 'List of enabled tool names' })
async getToolNames(): Promise<string[]> {
return this.systemPromptsService.getToolNames();
}
@Get('all-tools')
@ApiOperation({ summary: 'Get all available tool names' })
@ApiResponse({ status: 200, description: 'List of all tool names' })
async getAllToolNames(): Promise<{ tools: string[] }> {
const tools = this.systemPromptsService.getAllToolNames();
return { tools };
}
@Get('all-mcp-tools')
@ApiOperation({
summary: 'Get all available MCP tool names (serverName__toolName format)',
})
@ApiResponse({ status: 200, description: 'List of available MCP tool names' })
async getAllMcpToolNames(): Promise<{ mcpTools: string[] }> {
const mcpTools = await this.systemPromptsService.getAllMcpToolNames();
return { mcpTools };
}
@Get()
@ApiOperation({ summary: 'List all system prompts' })
@ApiResponse({
status: 200,
description: 'List of system prompts',
type: [SystemPrompt],
})
async findAll(): Promise<SystemPrompt[]> {
return this.systemPromptsService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get a system prompt by ID' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({
status: 200,
description: 'System prompt found',
type: SystemPrompt,
})
@ApiResponse({ status: 404, description: 'System prompt not found' })
async findOne(@Param('id', ParseUUIDPipe) id: string): Promise<SystemPrompt> {
return this.systemPromptsService.findOne(id);
}
@Get(':id/raw')
@ApiOperation({ summary: 'Get raw system prompt content (unrendered)' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({
status: 200,
description: 'Raw system prompt',
type: SystemPrompt,
})
@ApiResponse({ status: 404, description: 'System prompt not found' })
async findOneRaw(
@Param('id', ParseUUIDPipe) id: string,
): Promise<SystemPrompt> {
return this.systemPromptsService.findOneRaw(id);
}
@Get(':id/enabled-tools')
@ApiOperation({ summary: 'Get enabled tools for a system prompt' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Enabled tools list or "all"' })
async getEnabledTools(
@Param('id', ParseUUIDPipe) id: string,
): Promise<{ enabledTools: string[] | 'all' }> {
const enabledTools = await this.systemPromptsService.getEnabledTools(id);
return { enabledTools };
}
@Get(':id/tools-for-prompt')
@ApiOperation({
summary: 'Get tool definitions formatted for prompt injection',
})
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Tool definitions for prompt' })
async getToolsForPrompt(
@Param('id', ParseUUIDPipe) id: string,
): Promise<{ tools: string[] }> {
const tools = await this.systemPromptsService.getToolsForPrompt(id);
return { tools };
}
@Patch(':id/enabled-tools')
@ApiOperation({ summary: 'Set enabled tools for a system prompt' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Enabled tools updated' })
async setEnabledTools(
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: SetEnabledToolsDto,
): Promise<{ enabledTools: string[] | 'all' }> {
const enabledTools =
dto.enabledTools !== undefined
? dto.enabledTools
: dto.enabledToolsArray || 'all';
const updated = await this.systemPromptsService.setEnabledTools(
id,
enabledTools,
);
return { enabledTools: updated.enabledTools };
}
@Patch(':id/toggle-tool')
@ApiOperation({ summary: 'Toggle a single tool on/off' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Tool toggled' })
async toggleTool(
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: ToggleToolDto,
): Promise<{ enabledTools: string[] | 'all' }> {
const updated = await this.systemPromptsService.toggleTool(
id,
dto.toolName,
);
return { enabledTools: updated.enabledTools };
}
@Get(':id/enabled-mcp-tools')
@ApiOperation({
summary: 'Get enabled MCP tools for a system prompt',
})
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Enabled MCP tools list or "all"' })
async getEnabledMcpTools(
@Param('id', ParseUUIDPipe) id: string,
): Promise<{ enabledMcpTools: string[] | 'all' }> {
const enabledMcpTools =
await this.systemPromptsService.getEnabledMcpTools(id);
return { enabledMcpTools };
}
@Get(':id/mcp-tools-for-prompt')
@ApiOperation({
summary:
'Get MCP tool names that should be sent to LLM for a system prompt (considers both global and prompt-level settings)',
})
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Resolved MCP tool names' })
async getMcpToolsForPrompt(
@Param('id', ParseUUIDPipe) id: string,
): Promise<{ mcpTools: string[] }> {
const mcpTools = await this.systemPromptsService.getMcpToolsForPrompt(id);
return { mcpTools };
}
@Patch(':id/enabled-mcp-tools')
@ApiOperation({ summary: 'Set enabled MCP tools for a system prompt' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Enabled MCP tools updated' })
async setEnabledMcpTools(
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: SetEnabledMcpToolsDto,
): Promise<{ enabledMcpTools: string[] | 'all' }> {
const enabledMcpTools =
dto.enabledMcpTools !== undefined
? dto.enabledMcpTools
: dto.enabledMcpToolsArray || 'all';
const updated = await this.systemPromptsService.setEnabledMcpTools(
id,
enabledMcpTools,
);
return { enabledMcpTools: updated.enabledMcpTools };
}
@Patch(':id/toggle-mcp-tool')
@ApiOperation({
summary: 'Toggle a single MCP tool on/off for a system prompt',
})
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'MCP tool toggled' })
async toggleMcpTool(
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: ToggleMcpToolDto,
): Promise<{ enabledMcpTools: string[] | 'all' }> {
const updated = await this.systemPromptsService.toggleMcpTool(
id,
dto.mcpToolName,
);
return { enabledMcpTools: updated.enabledMcpTools };
}
@Put(':id')
@ApiOperation({ summary: 'Update a system prompt' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({
status: 200,
description: 'System prompt updated',
type: SystemPrompt,
})
@ApiResponse({ status: 403, description: 'Cannot modify built-in prompt' })
@ApiResponse({ status: 404, description: 'System prompt not found' })
async update(
@Param('id', ParseUUIDPipe) id: string,
@Body() updateSystemPromptDto: UpdateSystemPromptDto,
): Promise<SystemPrompt> {
return this.systemPromptsService.update(id, updateSystemPromptDto);
}
@Post(':id/set-default')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Set this prompt as the default' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({
status: 200,
description: 'Set as default',
type: SystemPrompt,
})
@ApiResponse({ status: 404, description: 'System prompt not found' })
async setDefault(
@Param('id', ParseUUIDPipe) id: string,
): Promise<SystemPrompt> {
return this.systemPromptsService.setDefault(id);
}
@Post(':id/push-to-studio')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Push system prompt to AI Studio' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 200, description: 'Pushed to studio' })
async pushToStudio(
@Param('id', ParseUUIDPipe) id: string,
): Promise<{ success: boolean }> {
await this.systemPromptsService.pushToStudio(id);
return { success: true };
}
@Post(':id/duplicate')
@HttpCode(HttpStatus.CREATED)
@ApiOperation({ summary: 'Duplicate a system prompt' })
@ApiParam({
name: 'id',
description: 'System prompt UUID to duplicate',
format: 'uuid',
})
@ApiResponse({
status: 201,
description: 'System prompt duplicated',
type: SystemPrompt,
})
@ApiResponse({ status: 404, description: 'System prompt not found' })
async duplicate(
@Param('id', ParseUUIDPipe) id: string,
): Promise<SystemPrompt> {
return this.systemPromptsService.duplicate(id);
}
@Delete(':id')
@HttpCode(HttpStatus.NO_CONTENT)
@ApiOperation({ summary: 'Delete a system prompt' })
@ApiParam({ name: 'id', description: 'System prompt UUID', format: 'uuid' })
@ApiResponse({ status: 204, description: 'System prompt deleted' })
@ApiResponse({ status: 403, description: 'Cannot delete built-in prompt' })
@ApiResponse({ status: 404, description: 'System prompt not found' })
async remove(@Param('id', ParseUUIDPipe) id: string): Promise<void> {
return this.systemPromptsService.remove(id);
}
}
|