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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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/**
 * Structured Prompting Frameworks
 * Pre-built templates to help users write better prompts
 */

export interface Framework {
    id: string
    name: string
    description: string
    sections: FrameworkSection[]
    example?: string
}

export interface FrameworkSection {
    id: string
    label: string
    description: string
    placeholder: string
    required: boolean
}

export const FRAMEWORKS: Record<string, Framework> = {
    RACE: {
        id: 'RACE',
        name: 'RACE',
        description: 'Role, Action, Context, Expectation - Clear structure for task-based prompts',
        sections: [
            {
                id: 'role',
                label: 'Role',
                description: 'What role should the AI take?',
                placeholder: 'e.g., "You are a senior software engineer..."',
                required: true,
            },
            {
                id: 'action',
                label: 'Action',
                description: 'What should the AI do?',
                placeholder: 'e.g., "Review this code and suggest improvements..."',
                required: true,
            },
            {
                id: 'context',
                label: 'Context',
                description: 'What background information is relevant?',
                placeholder: 'e.g., "This is a React component for a production app..."',
                required: true,
            },
            {
                id: 'expectation',
                label: 'Expectation',
                description: 'What format/style do you want?',
                placeholder: 'e.g., "Provide feedback as a bulleted list..."',
                required: true,
            },
        ],
        example: 'You are a senior software engineer. Review this code and suggest improvements. This is a React component for a production app with 10K users. Provide feedback as a bulleted list with code examples.',
    },

    CARE: {
        id: 'CARE',
        name: 'CARE',
        description: 'Context, Action, Result, Example - Perfect for generating content',
        sections: [
            {
                id: 'context',
                label: 'Context',
                description: 'Set the scene',
                placeholder: 'e.g., "I run a B2B SaaS startup..."',
                required: true,
            },
            {
                id: 'action',
                label: 'Action',
                description: 'What to create',
                placeholder: 'e.g., "Write a blog post about..."',
                required: true,
            },
            {
                id: 'result',
                label: 'Result',
                description: 'Desired outcome',
                placeholder: 'e.g., "Should be 1000 words, SEO optimized..."',
                required: true,
            },
            {
                id: 'example',
                label: 'Example',
                description: 'Show what good looks like',
                placeholder: 'e.g., "Similar to this style: [link]"',
                required: false,
            },
        ],
    },

    APE: {
        id: 'APE',
        name: 'APE',
        description: 'Action, Purpose, Expectation - Simple and effective',
        sections: [
            {
                id: 'action',
                label: 'Action',
                description: 'What to do',
                placeholder: 'e.g., "Generate 10 headline ideas..."',
                required: true,
            },
            {
                id: 'purpose',
                label: 'Purpose',
                description: 'Why you need it',
                placeholder: 'e.g., "For a product launch email campaign..."',
                required: true,
            },
            {
                id: 'expectation',
                label: 'Expectation',
                description: 'Format and style',
                placeholder: 'e.g., "Short, punchy, under 60 characters..."',
                required: true,
            },
        ],
    },

    CREATE: {
        id: 'CREATE',
        name: 'CREATE',
        description: 'Character, Request, Examples, Adjustments, Type, Extras - Most comprehensive',
        sections: [
            {
                id: 'character',
                label: 'Character',
                description: 'AI persona',
                placeholder: 'e.g., "Expert marketing copywriter..."',
                required: true,
            },
            {
                id: 'request',
                label: 'Request',
                description: 'Main task',
                placeholder: 'e.g., "Write ad copy for..."',
                required: true,
            },
            {
                id: 'examples',
                label: 'Examples',
                description: 'Sample outputs',
                placeholder: 'e.g., "Like this: [example]"',
                required: false,
            },
            {
                id: 'adjustments',
                label: 'Adjustments',
                description: 'Constraints',
                placeholder: 'e.g., "Max 150 characters, casual tone..."',
                required: false,
            },
            {
                id: 'type',
                label: 'Type',
                description: 'Output format',
                placeholder: 'e.g., "Bulleted list, JSON, table..."',
                required: true,
            },
            {
                id: 'extras',
                label: 'Extras',
                description: 'Additional notes',
                placeholder: 'e.g., "Focus on benefits not features..."',
                required: false,
            },
        ],
    },

    RISEN: {
        id: 'RISEN',
        name: 'RISEN',
        description: 'Role, Instructions, Steps, End goal, Narrowing - For complex tasks',
        sections: [
            {
                id: 'role',
                label: 'Role',
                description: 'AI identity',
                placeholder: 'e.g., "Professional business consultant..."',
                required: true,
            },
            {
                id: 'instructions',
                label: 'Instructions',
                description: 'High-level guidance',
                placeholder: 'e.g., "Analyze this business plan..."',
                required: true,
            },
            {
                id: 'steps',
                label: 'Steps',
                description: 'Break it down',
                placeholder: 'e.g., "1. Review financials, 2. Assess market..."',
                required: false,
            },
            {
                id: 'endGoal',
                label: 'End Goal',
                description: 'Success criteria',
                placeholder: 'e.g., "Provide actionable recommendations..."',
                required: true,
            },
            {
                id: 'narrowing',
                label: 'Narrowing',
                description: 'Scope limits',
                placeholder: 'e.g., "Focus only on Q4 2025..."',
                required: false,
            },
        ],
    },

    RTF: {
        id: 'RTF',
        name: 'RTF',
        description: 'Role, Task, Format - Quick and simple',
        sections: [
            {
                id: 'role',
                label: 'Role',
                description: 'Who is the AI?',
                placeholder: 'e.g., "You are a helpful assistant..."',
                required: true,
            },
            {
                id: 'task',
                label: 'Task',
                description: 'What to do',
                placeholder: 'e.g., "Summarize this article..."',
                required: true,
            },
            {
                id: 'format',
                label: 'Format',
                description: 'How to present',
                placeholder: 'e.g., "5 bullet points, max 20 words each..."',
                required: true,
            },
        ],
    },

    TAG: {
        id: 'TAG',
        name: 'TAG',
        description: 'Task, Action, Goal - Minimal but effective',
        sections: [
            {
                id: 'task',
                label: 'Task',
                description: 'What needs doing',
                placeholder: 'e.g., "Write product description..."',
                required: true,
            },
            {
                id: 'action',
                label: 'Action',
                description: 'Specific steps',
                placeholder: 'e.g., "Highlight key features and benefits..."',
                required: true,
            },
            {
                id: 'goal',
                label: 'Goal',
                description: 'Success metric',
                placeholder: 'e.g., "Convert visitors to customers..."',
                required: true,
            },
        ],
    },

    BAB: {
        id: 'BAB',
        name: 'BAB',
        description: 'Before, After, Bridge - For transformation stories',
        sections: [
            {
                id: 'before',
                label: 'Before',
                description: 'Current state',
                placeholder: 'e.g., "Customer struggles with..."',
                required: true,
            },
            {
                id: 'after',
                label: 'After',
                description: 'Desired state',
                placeholder: 'e.g., "Customer achieves..."',
                required: true,
            },
            {
                id: 'bridge',
                label: 'Bridge',
                description: 'How to get there',
                placeholder: 'e.g., "Using our product..."',
                required: true,
            },
        ],
    },

    STAR: {
        id: 'STAR',
        name: 'STAR',
        description: 'Situation, Task, Action, Result - For case studies',
        sections: [
            {
                id: 'situation',
                label: 'Situation',
                description: 'Context',
                placeholder: 'e.g., "Company faced declining sales..."',
                required: true,
            },
            {
                id: 'task',
                label: 'Task',
                description: 'Challenge',
                placeholder: 'e.g., "Needed to increase conversion by 20%..."',
                required: true,
            },
            {
                id: 'action',
                label: 'Action',
                description: 'What happened',
                placeholder: 'e.g., "Implemented new email strategy..."',
                required: true,
            },
            {
                id: 'result',
                label: 'Result',
                description: 'Outcome',
                placeholder: 'e.g., "Achieved 35% increase in 3 months..."',
                required: true,
            },
        ],
    },

    PREP: {
        id: 'PREP',
        name: 'PREP',
        description: 'Point, Reason, Example, Point - For persuasive content',
        sections: [
            {
                id: 'point',
                label: 'Point',
                description: 'Main argument',
                placeholder: 'e.g., "AI will transform healthcare..."',
                required: true,
            },
            {
                id: 'reason',
                label: 'Reason',
                description: 'Why it matters',
                placeholder: 'e.g., "Because it can analyze data faster..."',
                required: true,
            },
            {
                id: 'example',
                label: 'Example',
                description: 'Proof',
                placeholder: 'e.g., "Studies show 90% accuracy in diagnosis..."',
                required: true,
            },
            {
                id: 'pointAgain',
                label: 'Point (Restate)',
                description: 'Reinforce',
                placeholder: 'e.g., "This is why AI is the future of healthcare..."',
                required: true,
            },
        ],
    },
}

/**
 * Generate prompt template from framework and filled sections
 */
export function generateFromFramework(
    framework: Framework,
    sections: Record<string, string>
): string {
    const parts: string[] = []

    framework.sections.forEach((section) => {
        const value = sections[section.id]
        if (value) {
            parts.push(value)
        }
    })

    return parts.join('\n\n')
}

/**
 * Get framework by ID
 */
export function getFramework(id: string): Framework | undefined {
    return FRAMEWORKS[id]
}

/**
 * Get all frameworks as array
 */
export function getAllFrameworks(): Framework[] {
    return Object.values(FRAMEWORKS)
}

/**
 * Detect which framework a prompt might be using
 */
export function detectFramework(template: string): string | null {
    // Simple heuristic based on keywords
    const lower = template.toLowerCase()

    if (lower.includes('you are') && lower.includes('context') && lower.includes('expectation')) {
        return 'RACE'
    }
    if (lower.includes('before') && lower.includes('after')) {
        return 'BAB'
    }
    if (lower.includes('situation') && lower.includes('task') && lower.includes('result')) {
        return 'STAR'
    }

    return null
}