Spaces:
Running
Running
| /** | |
| * Seed script to populate prompt_templates table from TypeScript files | |
| * | |
| * This script: | |
| * 1. Reads student prompts from src/lib/prompts/student-prompts.ts | |
| * 2. Reads coach prompts from src/lib/prompts/coach-prompts.ts | |
| * 3. Inserts them into the database | |
| * 4. Is idempotent: safe to run multiple times (skips existing prompts) | |
| * | |
| * Usage: | |
| * npm run db:seed | |
| * tsx src/scripts/seed-prompts.ts | |
| */ | |
| import { studentPrompts } from '../lib/prompts/student-prompts'; | |
| import { COACH_PERSONAS } from '../lib/prompts/coach-prompts'; | |
| import { evaluationPrompts } from '../lib/prompts/evaluation-prompts'; | |
| import { PromptTemplateRepository } from '../lib/repositories/prompt-template-repository'; | |
| import { EvaluationPromptRepository } from '../lib/repositories/evaluation-prompt-repository'; | |
| async function seedPrompts() { | |
| console.log('[Seed] Starting prompt template seeding...\n'); | |
| const repo = new PromptTemplateRepository(); | |
| const evalRepo = new EvaluationPromptRepository(); | |
| let created = 0; | |
| let skipped = 0; | |
| let errors = 0; | |
| // Seed student prompts | |
| console.log('[Seed] Seeding student prompts...'); | |
| for (const [id, config] of Object.entries(studentPrompts)) { | |
| try { | |
| // Check if prompt already exists | |
| const existing = await repo.findById(id); | |
| if (existing) { | |
| console.log(` βοΈ Skipping ${id} (already exists)`); | |
| skipped++; | |
| continue; | |
| } | |
| // Create new prompt | |
| await repo.create({ | |
| id, | |
| type: 'student', | |
| name: config.name, | |
| description: config.description, | |
| systemPrompt: config.systemPrompt, | |
| }); | |
| console.log(` β Created ${id}: ${config.name}`); | |
| created++; | |
| } catch (error) { | |
| console.error(` β Error creating ${id}:`, error); | |
| errors++; | |
| } | |
| } | |
| // Seed coach prompts | |
| console.log('\n[Seed] Seeding coach prompts...'); | |
| for (const [id, config] of Object.entries(COACH_PERSONAS)) { | |
| try { | |
| // Check if prompt already exists | |
| const existing = await repo.findById(id); | |
| if (existing) { | |
| console.log(` βοΈ Skipping ${id} (already exists)`); | |
| skipped++; | |
| continue; | |
| } | |
| // Create new prompt | |
| await repo.create({ | |
| id, | |
| type: 'coach', | |
| name: config.name, | |
| description: config.description, | |
| systemPrompt: config.systemPrompt, | |
| }); | |
| console.log(` β Created ${id}: ${config.name}`); | |
| created++; | |
| } catch (error) { | |
| console.error(` β Error creating ${id}:`, error); | |
| errors++; | |
| } | |
| } | |
| // Seed evaluation prompts | |
| console.log('\n[Seed] Seeding evaluation prompts...'); | |
| for (const [id, config] of Object.entries(evaluationPrompts)) { | |
| try { | |
| // Check if prompt already exists | |
| const existing = await evalRepo.findById(id); | |
| if (existing) { | |
| console.log(` βοΈ Skipping ${id} (already exists)`); | |
| skipped++; | |
| continue; | |
| } | |
| // Create new prompt | |
| await evalRepo.create({ | |
| id, | |
| name: config.name, | |
| description: config.description, | |
| systemPrompt: config.systemPrompt, | |
| }); | |
| console.log(` β Created ${id}: ${config.name}`); | |
| created++; | |
| } catch (error) { | |
| console.error(` β Error creating ${id}:`, error); | |
| errors++; | |
| } | |
| } | |
| // Summary | |
| console.log('\n[Seed] Summary:'); | |
| console.log(` β Created: ${created}`); | |
| console.log(` βοΈ Skipped: ${skipped}`); | |
| console.log(` β Errors: ${errors}`); | |
| if (errors > 0) { | |
| console.error('\n[Seed] β Seeding completed with errors'); | |
| process.exit(1); | |
| } else { | |
| console.log('\n[Seed] β Seeding completed successfully'); | |
| process.exit(0); | |
| } | |
| } | |
| // Run the seed function | |
| seedPrompts().catch(error => { | |
| console.error('[Seed] Fatal error:', error); | |
| process.exit(1); | |
| }); | |