prompts.chat 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +856 -0
  2. package/dist/builder/index.d.mts +1067 -0
  3. package/dist/builder/index.d.ts +1067 -0
  4. package/dist/builder/index.js +2471 -0
  5. package/dist/builder/index.js.map +1 -0
  6. package/dist/builder/index.mjs +2432 -0
  7. package/dist/builder/index.mjs.map +1 -0
  8. package/dist/index-BEIO8LCd.d.mts +61 -0
  9. package/dist/index-BEIO8LCd.d.ts +61 -0
  10. package/dist/index-CSHEKYfQ.d.mts +64 -0
  11. package/dist/index-CSHEKYfQ.d.ts +64 -0
  12. package/dist/index-D41E6D9X.d.mts +77 -0
  13. package/dist/index-D41E6D9X.d.ts +77 -0
  14. package/dist/index-DOz8zcA0.d.mts +68 -0
  15. package/dist/index-DOz8zcA0.d.ts +68 -0
  16. package/dist/index.d.mts +5 -0
  17. package/dist/index.d.ts +5 -0
  18. package/dist/index.js +3335 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/index.mjs +3276 -0
  21. package/dist/index.mjs.map +1 -0
  22. package/dist/parser/index.d.mts +1 -0
  23. package/dist/parser/index.d.ts +1 -0
  24. package/dist/parser/index.js +288 -0
  25. package/dist/parser/index.js.map +1 -0
  26. package/dist/parser/index.mjs +259 -0
  27. package/dist/parser/index.mjs.map +1 -0
  28. package/dist/quality/index.d.mts +1 -0
  29. package/dist/quality/index.d.ts +1 -0
  30. package/dist/quality/index.js +212 -0
  31. package/dist/quality/index.js.map +1 -0
  32. package/dist/quality/index.mjs +184 -0
  33. package/dist/quality/index.mjs.map +1 -0
  34. package/dist/similarity/index.d.mts +1 -0
  35. package/dist/similarity/index.d.ts +1 -0
  36. package/dist/similarity/index.js +123 -0
  37. package/dist/similarity/index.js.map +1 -0
  38. package/dist/similarity/index.mjs +91 -0
  39. package/dist/similarity/index.mjs.map +1 -0
  40. package/dist/variables/index.d.mts +1 -0
  41. package/dist/variables/index.d.ts +1 -0
  42. package/dist/variables/index.js +306 -0
  43. package/dist/variables/index.js.map +1 -0
  44. package/dist/variables/index.mjs +274 -0
  45. package/dist/variables/index.mjs.map +1 -0
  46. package/package.json +77 -6
package/README.md ADDED
@@ -0,0 +1,856 @@
1
+ # prompts.chat
2
+
3
+ The **D3.js of prompt engineering** — a comprehensive developer toolkit for building, validating, and parsing AI prompts. Create structured prompts for chat models, image generators, video AI, and music generation with fluent, type-safe APIs.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install prompts.chat
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { builder, chat, image, audio, variables, quality } from 'prompts.chat';
15
+
16
+ // Build structured text prompts
17
+ const prompt = builder()
18
+ .role("Senior TypeScript Developer")
19
+ .task("Review the following code for bugs and improvements")
20
+ .constraints(["Be concise", "Focus on critical issues"])
21
+ .variable("code", { required: true })
22
+ .build();
23
+
24
+ // Build chat prompts with full control
25
+ const chatPrompt = chat()
26
+ .role("expert code reviewer")
27
+ .tone("professional")
28
+ .expertise("TypeScript", "React", "Node.js")
29
+ .task("Review code and provide actionable feedback")
30
+ .stepByStep()
31
+ .json()
32
+ .build();
33
+
34
+ // Build image generation prompts
35
+ const imagePrompt = image()
36
+ .subject("a cyberpunk samurai")
37
+ .environment("neon-lit Tokyo streets")
38
+ .shot("medium")
39
+ .lens("35mm")
40
+ .lightingType("neon")
41
+ .medium("cinematic")
42
+ .build();
43
+
44
+ // Build music generation prompts
45
+ const musicPrompt = audio()
46
+ .genre("electronic")
47
+ .mood("energetic")
48
+ .bpm(128)
49
+ .instruments(["synthesizer", "drums", "bass"])
50
+ .build();
51
+
52
+ // Normalize variable formats
53
+ const normalized = variables.normalize("Hello {{name}}, you are [ROLE]");
54
+ // → "Hello ${name}, you are ${role}"
55
+
56
+ // Check quality locally (no API needed)
57
+ const result = quality.check("Act as a developer...");
58
+ console.log(result.score); // 0.85
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Modules
64
+
65
+ - [Variables](#-variables) — Variable detection and normalization
66
+ - [Similarity](#-similarity) — Content deduplication
67
+ - [Builder](#️-builder) — Structured text prompts
68
+ - [Chat Builder](#-chat-builder) — Chat/conversational prompts
69
+ - [Image Builder](#-image-builder) — Image generation prompts
70
+ - [Video Builder](#-video-builder) — Video generation prompts
71
+ - [Audio Builder](#-audio-builder) — Music/audio generation prompts
72
+ - [Quality](#-quality) — Prompt validation
73
+ - [Parser](#-parser) — Multi-format parsing
74
+
75
+ ---
76
+
77
+ ## 🔧 Variables
78
+
79
+ Universal variable detection and normalization across different formats.
80
+
81
+ ```typescript
82
+ import { variables } from 'prompts.chat';
83
+
84
+ // Detect variables in any format
85
+ const detected = variables.detect("Hello {{name}}, welcome to [COMPANY]");
86
+ // → [{ name: "name", pattern: "double_curly" }, { name: "COMPANY", pattern: "single_bracket" }]
87
+
88
+ // Normalize all formats to ${var}
89
+ const normalized = variables.normalize("Hello {{name}}, you are [ROLE]");
90
+ // → "Hello ${name}, you are ${role}"
91
+
92
+ // Extract variables from ${var} format
93
+ const vars = variables.extractVariables("Hello ${name:World}");
94
+ // → [{ name: "name", defaultValue: "World" }]
95
+
96
+ // Compile template with values
97
+ const result = variables.compile("Hello ${name:World}", { name: "Developer" });
98
+ // → "Hello Developer"
99
+
100
+ // Get pattern descriptions
101
+ variables.getPatternDescription("double_bracket"); // → "[[...]]"
102
+ ```
103
+
104
+ ### Supported Formats
105
+
106
+ | Format | Example | Pattern Name |
107
+ |--------|---------|--------------|
108
+ | `${var}` | `${name}` | `dollar_curly` |
109
+ | `${var:default}` | `${name:World}` | `dollar_curly` |
110
+ | `{{var}}` | `{{name}}` | `double_curly` |
111
+ | `[[var]]` | `[[name]]` | `double_bracket` |
112
+ | `[VAR]` | `[NAME]` | `single_bracket` |
113
+ | `{VAR}` | `{NAME}` | `single_curly` |
114
+ | `<VAR>` | `<NAME>` | `angle_bracket` |
115
+ | `%VAR%` | `%NAME%` | `percent` |
116
+
117
+ ### API Reference
118
+
119
+ | Function | Description |
120
+ |----------|-------------|
121
+ | `detect(text)` | Detect variables in any format |
122
+ | `normalize(text)` | Convert all formats to `${var}` |
123
+ | `extractVariables(text)` | Extract from `${var}` format |
124
+ | `compile(text, values, options?)` | Replace variables with values |
125
+ | `convertToSupportedFormat(variable)` | Convert a single variable |
126
+ | `getPatternDescription(pattern)` | Get human-readable pattern |
127
+
128
+ ---
129
+
130
+ ## 📊 Similarity
131
+
132
+ Content similarity detection for deduplication using Jaccard and n-gram algorithms.
133
+
134
+ ```typescript
135
+ import { similarity } from 'prompts.chat';
136
+
137
+ // Calculate similarity score (0-1)
138
+ const score = similarity.calculate(prompt1, prompt2);
139
+ // → 0.87
140
+
141
+ // Check if prompts are duplicates (default threshold: 0.85)
142
+ const isDupe = similarity.isDuplicate(prompt1, prompt2, 0.85);
143
+ // → true
144
+
145
+ // Find groups of duplicate prompts
146
+ const groups = similarity.findDuplicates(prompts, 0.85);
147
+ // → [[prompt1, prompt3], [prompt2, prompt5]]
148
+
149
+ // Deduplicate an array (keeps first occurrence)
150
+ const unique = similarity.deduplicate(prompts, 0.85);
151
+
152
+ // Get content fingerprint for indexing
153
+ const fingerprint = similarity.getContentFingerprint(prompt);
154
+
155
+ // Normalize content for comparison
156
+ const normalized = similarity.normalizeContent(text);
157
+ ```
158
+
159
+ ### API Reference
160
+
161
+ | Function | Description |
162
+ |----------|-------------|
163
+ | `calculate(content1, content2)` | Calculate similarity score (0-1) |
164
+ | `isDuplicate(content1, content2, threshold?)` | Check if similar (default 0.85) |
165
+ | `findDuplicates(prompts, threshold?)` | Find groups of duplicates |
166
+ | `deduplicate(prompts, threshold?)` | Remove duplicates |
167
+ | `normalizeContent(content)` | Normalize for comparison |
168
+ | `getContentFingerprint(content)` | Get fingerprint for indexing |
169
+
170
+ ---
171
+
172
+ ## 🏗️ Builder
173
+
174
+ Fluent DSL for creating structured text prompts.
175
+
176
+ ```typescript
177
+ import { builder, fromPrompt, templates } from 'prompts.chat';
178
+
179
+ // Build a custom prompt
180
+ const prompt = builder()
181
+ .role("Senior Developer")
182
+ .context("You are helping review a React application")
183
+ .task("Analyze the code for performance issues")
184
+ .constraints([
185
+ "Be concise",
186
+ "Focus on critical issues",
187
+ "Suggest fixes with code examples"
188
+ ])
189
+ .output("JSON with { issues: [], suggestions: [] }")
190
+ .variable("code", { required: true, description: "Code to review" })
191
+ .example("const x = 1;", '{ "issues": [], "suggestions": [] }')
192
+ .section("Additional Notes", "Consider React 18 best practices")
193
+ .build();
194
+
195
+ console.log(prompt.content);
196
+ console.log(prompt.variables);
197
+ console.log(prompt.metadata);
198
+
199
+ // Create from existing prompt
200
+ const existing = fromPrompt("You are a helpful assistant...").build();
201
+ ```
202
+
203
+ ### Builder Methods
204
+
205
+ | Method | Description |
206
+ |--------|-------------|
207
+ | `.role(role)` | Set AI persona (alias: `.persona()`) |
208
+ | `.context(context)` | Set background info (alias: `.background()`) |
209
+ | `.task(task)` | Set main instruction (alias: `.instruction()`) |
210
+ | `.constraints(list)` | Add multiple constraints (alias: `.rules()`) |
211
+ | `.constraint(text)` | Add single constraint |
212
+ | `.output(format)` | Set output format (alias: `.format()`) |
213
+ | `.example(input, output)` | Add input/output example |
214
+ | `.examples(list)` | Add multiple examples |
215
+ | `.variable(name, options?)` | Define a variable |
216
+ | `.section(title, content)` | Add custom section |
217
+ | `.raw(content)` | Set raw content |
218
+ | `.build()` | Build the prompt |
219
+ | `.toString()` | Get content string |
220
+
221
+ ### Pre-built Templates
222
+
223
+ ```typescript
224
+ import { templates } from 'prompts.chat';
225
+
226
+ // Code review template
227
+ const review = templates.codeReview({
228
+ language: "TypeScript",
229
+ focus: ["performance", "security"]
230
+ });
231
+
232
+ // Translation template
233
+ const translate = templates.translation("English", "Spanish");
234
+
235
+ // Summarization template
236
+ const summary = templates.summarize({
237
+ maxLength: 100,
238
+ style: "bullet"
239
+ });
240
+
241
+ // Q&A template
242
+ const qa = templates.qa("You are answering questions about React.");
243
+ ```
244
+
245
+ ---
246
+
247
+ ## 💬 Chat Builder
248
+
249
+ Model-agnostic builder for conversational AI prompts. Works with GPT-4, Claude, Gemini, and any chat model.
250
+
251
+ ```typescript
252
+ import { chat, chatPresets } from 'prompts.chat';
253
+
254
+ const prompt = chat()
255
+ // Persona
256
+ .role("senior software architect")
257
+ .tone("professional", "analytical")
258
+ .expertise("system design", "microservices", "cloud architecture")
259
+
260
+ // Context
261
+ .context("Designing a scalable e-commerce platform")
262
+ .domain("software engineering")
263
+
264
+ // Task
265
+ .task("Review the architecture proposal and provide feedback")
266
+ .objectives(["Identify bottlenecks", "Suggest improvements"])
267
+
268
+ // Constraints
269
+ .constraints(["Focus on scalability", "Consider cost"])
270
+ .avoid(["Over-engineering", "Vendor lock-in"])
271
+
272
+ // Reasoning
273
+ .stepByStep()
274
+ .showReasoning()
275
+
276
+ // Output
277
+ .json({ schema: { type: "object", properties: { feedback: { type: "array" } } } })
278
+ .detailed()
279
+
280
+ // Examples
281
+ .example("Simple API design", "Consider using API Gateway for rate limiting...")
282
+
283
+ // Messages
284
+ .user("Here's my architecture proposal...")
285
+ .build();
286
+
287
+ // Access outputs
288
+ console.log(prompt.systemPrompt); // Full system prompt
289
+ console.log(prompt.messages); // Message array
290
+ console.log(prompt.userPrompt); // Latest user message
291
+
292
+ // Output formats
293
+ const yaml = prompt.toYAML();
294
+ const md = prompt.toMarkdown();
295
+ const json = prompt.toJSON();
296
+ ```
297
+
298
+ ### Chat Builder Methods
299
+
300
+ #### Persona
301
+ | Method | Description |
302
+ |--------|-------------|
303
+ | `.role(role)` | Set the AI's role |
304
+ | `.tone(tones...)` | Set communication tone(s) |
305
+ | `.expertise(areas...)` | Define expertise areas |
306
+ | `.personality(traits...)` | Set personality traits |
307
+
308
+ #### Context
309
+ | Method | Description |
310
+ |--------|-------------|
311
+ | `.context(text)` | Set situation context |
312
+ | `.domain(domain)` | Set knowledge domain |
313
+ | `.audience(audience)` | Define target audience |
314
+ | `.background(text)` | Add background info |
315
+
316
+ #### Task
317
+ | Method | Description |
318
+ |--------|-------------|
319
+ | `.task(description)` | Main task description |
320
+ | `.objectives(list)` | Add objectives |
321
+ | `.scope(scope)` | Define scope |
322
+ | `.priority(priority)` | Set priority |
323
+
324
+ #### Constraints
325
+ | Method | Description |
326
+ |--------|-------------|
327
+ | `.constraints(list)` | Must-follow rules |
328
+ | `.avoid(list)` | Things to avoid |
329
+ | `.requirements(list)` | Requirements |
330
+
331
+ #### Reasoning
332
+ | Method | Description |
333
+ |--------|-------------|
334
+ | `.stepByStep()` | Enable step-by-step reasoning |
335
+ | `.showReasoning()` | Show reasoning process |
336
+ | `.thinkFirst()` | Think before answering |
337
+ | `.socratic()` | Use Socratic method |
338
+
339
+ #### Output
340
+ | Method | Description |
341
+ |--------|-------------|
342
+ | `.json(schema?)` | Output as JSON |
343
+ | `.markdown()` | Output as Markdown |
344
+ | `.yaml()` | Output as YAML |
345
+ | `.xml()` | Output as XML |
346
+ | `.code(language?)` | Output as code |
347
+ | `.concise()` | Brief output |
348
+ | `.detailed()` | Detailed output |
349
+ | `.comprehensive()` | Comprehensive output |
350
+
351
+ #### Messages
352
+ | Method | Description |
353
+ |--------|-------------|
354
+ | `.system(content)` | Add system message |
355
+ | `.user(content)` | Add user message |
356
+ | `.assistant(content)` | Add assistant message |
357
+ | `.example(input, output)` | Add few-shot example |
358
+ | `.memory(key, value, priority?)` | Store memory |
359
+
360
+ ### Chat Presets
361
+
362
+ ```typescript
363
+ import { chatPresets } from 'prompts.chat';
364
+
365
+ // Expert coder
366
+ const coder = chatPresets.coder("TypeScript");
367
+
368
+ // Creative writer
369
+ const writer = chatPresets.writer("technical");
370
+
371
+ // Patient tutor
372
+ const tutor = chatPresets.tutor("mathematics");
373
+
374
+ // Data analyst
375
+ const analyst = chatPresets.analyst();
376
+
377
+ // Socratic teacher
378
+ const socratic = chatPresets.socratic();
379
+
380
+ // JSON responder
381
+ const jsonBot = chatPresets.jsonResponder({
382
+ type: "object",
383
+ properties: { answer: { type: "string" } }
384
+ });
385
+
386
+ // Summarizer
387
+ const summarizer = chatPresets.summarizer(100);
388
+
389
+ // Translator
390
+ const translator = chatPresets.translator("English", "Japanese");
391
+ ```
392
+
393
+ ---
394
+
395
+ ## 🎨 Image Builder
396
+
397
+ Comprehensive builder for image generation prompts (Midjourney, DALL-E, Stable Diffusion, etc.).
398
+
399
+ ```typescript
400
+ import { image } from 'prompts.chat';
401
+
402
+ const prompt = image()
403
+ // Subject
404
+ .subject("a cyberpunk samurai warrior")
405
+ .subjectDetails({
406
+ pose: "dynamic battle stance",
407
+ expression: "determined",
408
+ clothing: "neon-lit armor with glowing circuits",
409
+ accessories: ["katana", "holographic visor"]
410
+ })
411
+
412
+ // Environment
413
+ .environment("rain-soaked Tokyo alley")
414
+ .setting("urban", "futuristic")
415
+ .atmosphere("electric", "mysterious")
416
+ .weather("rain")
417
+ .timeOfDay("night")
418
+
419
+ // Camera
420
+ .shot("medium")
421
+ .angle("low-angle")
422
+ .lens("35mm")
423
+ .aperture("f/1.8")
424
+ .focus("sharp")
425
+ .cameraBrand("Sony")
426
+ .cameraModel("A7R V")
427
+ .bokeh("smooth")
428
+
429
+ // Lighting
430
+ .lightingType("neon")
431
+ .lightingDirection("rim")
432
+ .lightingIntensity("dramatic")
433
+
434
+ // Style
435
+ .medium("cinematic")
436
+ .artStyle("cyberpunk")
437
+ .artist("Syd Mead")
438
+ .era("futuristic")
439
+ .filmStock("Kodak Vision3 500T")
440
+
441
+ // Color
442
+ .colorPalette("cyberpunk")
443
+ .colorGrade("teal and orange")
444
+ .saturation("vibrant")
445
+
446
+ // Technical
447
+ .resolution("8K")
448
+ .quality("ultra-detailed")
449
+ .aspectRatio("16:9")
450
+ .build();
451
+
452
+ console.log(prompt.prompt); // Text prompt
453
+ console.log(prompt.negativePrompt); // Negative prompt
454
+
455
+ // Output formats
456
+ const json = prompt.toJSON();
457
+ const yaml = prompt.toYAML();
458
+ const md = prompt.toMarkdown();
459
+ ```
460
+
461
+ ### Camera Options
462
+
463
+ | Category | Examples |
464
+ |----------|----------|
465
+ | **Brands** | Canon, Nikon, Sony, ARRI, RED, Hasselblad, Leica, Fujifilm |
466
+ | **Shot Types** | extreme-close-up, close-up, medium, full, wide, aerial |
467
+ | **Angles** | eye-level, low-angle, high-angle, dutch, bird's-eye, worm's-eye |
468
+ | **Lens Types** | wide, standard, telephoto, macro, fisheye, anamorphic |
469
+ | **Film Stocks** | Kodak Portra, Fuji Velvia, Kodak Vision3, Ilford HP5 |
470
+
471
+ ### Lighting Options
472
+
473
+ | Type | Examples |
474
+ |------|----------|
475
+ | **Lighting Types** | natural, studio, rim, butterfly, rembrandt, neon, volumetric |
476
+ | **Time of Day** | golden-hour, blue-hour, midday, sunset, night, dawn |
477
+ | **Weather** | clear, cloudy, rain, snow, fog, storm |
478
+
479
+ ### Style Options
480
+
481
+ | Category | Examples |
482
+ |----------|----------|
483
+ | **Art Styles** | photorealistic, anime, oil-painting, watercolor, cyberpunk, art-deco |
484
+ | **Mediums** | photography, cinematic, illustration, 3d-render, concept-art |
485
+ | **Color Palettes** | warm, cool, pastel, neon, monochrome, vintage |
486
+
487
+ ---
488
+
489
+ ## � Video Builder
490
+
491
+ Builder for video generation prompts (Sora, Runway, Pika, etc.).
492
+
493
+ ```typescript
494
+ import { video } from 'prompts.chat';
495
+
496
+ const prompt = video()
497
+ // Scene
498
+ .scene("A lone astronaut walks across the Martian surface")
499
+ .location("Mars", "Olympus Mons base camp")
500
+ .environment("dusty red landscape", "thin atmosphere")
501
+ .time("dusk")
502
+ .weather("dust storm approaching")
503
+
504
+ // Subject
505
+ .character("astronaut", {
506
+ appearance: "NASA spacesuit, reflective visor",
507
+ action: "walking purposefully",
508
+ emotion: "determined"
509
+ })
510
+
511
+ // Camera
512
+ .movement("tracking")
513
+ .shot("wide")
514
+ .angle("low-angle")
515
+ .speed("slow")
516
+ .lens("anamorphic")
517
+ .cameraBrand("ARRI")
518
+ .cameraModel("ALEXA 65")
519
+ .stabilization("gimbal")
520
+
521
+ // Motion
522
+ .pacing("slow")
523
+ .transitions("fade")
524
+ .motionBlur(true)
525
+
526
+ // Lighting
527
+ .lightingType("golden hour")
528
+ .lightingMood("epic")
529
+
530
+ // Style
531
+ .style("cinematic")
532
+ .colorGrade("orange and teal")
533
+ .filmGrain("subtle")
534
+ .styleFilmStock("Kodak Vision3 500T")
535
+
536
+ // Audio
537
+ .audioMood("epic orchestral")
538
+ .soundDesign("wind, footsteps, breathing")
539
+
540
+ // Technical
541
+ .duration(10)
542
+ .fps(24)
543
+ .resolution("4K")
544
+ .aspectRatio("2.39:1")
545
+ .build();
546
+
547
+ console.log(prompt.prompt);
548
+ console.log(prompt.structure);
549
+
550
+ // Output formats
551
+ const json = prompt.toJSON();
552
+ const yaml = prompt.toYAML();
553
+ ```
554
+
555
+ ### Video-Specific Options
556
+
557
+ | Category | Examples |
558
+ |----------|----------|
559
+ | **Camera Movement** | static, pan, tilt, dolly, tracking, crane, handheld, drone |
560
+ | **Transitions** | cut, fade, dissolve, wipe, zoom |
561
+ | **Pacing** | slow-motion, normal, fast-motion, timelapse |
562
+ | **Frame Rates** | 24, 30, 60, 120 fps |
563
+
564
+ ---
565
+
566
+ ## 🎵 Audio Builder
567
+
568
+ Builder for music and audio generation prompts (Suno, Udio, etc.).
569
+
570
+ ```typescript
571
+ import { audio } from 'prompts.chat';
572
+
573
+ const prompt = audio()
574
+ // Genre & Style
575
+ .genre("electronic")
576
+ .subgenre("synthwave")
577
+ .era("1980s")
578
+ .influences(["Kavinsky", "Carpenter Brut", "Perturbator"])
579
+
580
+ // Mood & Energy
581
+ .mood("nostalgic")
582
+ .energy("high")
583
+ .emotion("triumphant")
584
+
585
+ // Tempo & Rhythm
586
+ .bpm(120)
587
+ .feel("driving")
588
+ .groove("steady")
589
+
590
+ // Vocals
591
+ .vocalStyle("ethereal")
592
+ .vocalRange("tenor")
593
+ .lyrics("retro-futuristic themes")
594
+ .harmony("layered")
595
+
596
+ // Instrumentation
597
+ .instruments(["synthesizer", "drums", "bass", "electric guitar"])
598
+ .lead("analog synth lead")
599
+ .rhythm("drum machine")
600
+ .bass("deep sub bass")
601
+ .pads("lush synth pads")
602
+
603
+ // Structure
604
+ .intro("atmospheric build")
605
+ .verse("rhythmic drive")
606
+ .chorus("anthemic climax")
607
+ .bridge("breakdown")
608
+ .outro("fade out")
609
+ .duration(210) // 3:30
610
+
611
+ // Production
612
+ .productionStyle("polished")
613
+ .mixing("wide stereo")
614
+ .effects(["reverb", "delay", "sidechain compression"])
615
+
616
+ // Technical
617
+ .key("A minor")
618
+ .timeSignature("4/4")
619
+ .build();
620
+
621
+ console.log(prompt.stylePrompt);
622
+ console.log(prompt.lyricsPrompt);
623
+ console.log(prompt.structure);
624
+
625
+ // Output formats
626
+ const json = prompt.toJSON();
627
+ const yaml = prompt.toYAML();
628
+ ```
629
+
630
+ ### Audio Options
631
+
632
+ | Category | Examples |
633
+ |----------|----------|
634
+ | **Genres** | pop, rock, jazz, classical, electronic, hip-hop, ambient, cinematic |
635
+ | **Moods** | happy, sad, energetic, calm, dark, uplifting, melancholic |
636
+ | **Instruments** | piano, guitar, drums, bass, synthesizer, violin, saxophone |
637
+ | **Vocal Styles** | clean, breathy, raspy, falsetto, operatic, whispered |
638
+ | **Keys** | C major, A minor, G major, E minor, etc. |
639
+ | **Time Signatures** | 4/4, 3/4, 6/8, 5/4, 7/8 |
640
+
641
+ ---
642
+
643
+ ## ✅ Quality
644
+
645
+ Local prompt quality validation (no API required).
646
+
647
+ ```typescript
648
+ import { quality } from 'prompts.chat';
649
+
650
+ // Check prompt quality
651
+ const result = quality.check("Act as a senior developer...");
652
+
653
+ console.log(result.valid); // true
654
+ console.log(result.score); // 0.85 (0-1)
655
+ console.log(result.issues); // Array of issues
656
+ console.log(result.stats); // Detailed statistics
657
+
658
+ // Statistics include:
659
+ // - characterCount, wordCount, sentenceCount
660
+ // - variableCount
661
+ // - hasRole, hasTask, hasConstraints, hasExamples
662
+
663
+ // Validate (throws if invalid)
664
+ quality.validate(promptText);
665
+
666
+ // Check validity
667
+ const isValid = quality.isValid(promptText);
668
+
669
+ // Get improvement suggestions
670
+ const suggestions = quality.getSuggestions(promptText);
671
+ // → ["Add a role definition", "Consider adding examples"]
672
+ ```
673
+
674
+ ### Quality Checks
675
+
676
+ | Check | Type | Description |
677
+ |-------|------|-------------|
678
+ | `EMPTY` | error | Prompt is empty |
679
+ | `TOO_SHORT` | error | Below minimum length |
680
+ | `GIBBERISH` | error | Random/keyboard patterns |
681
+ | `FEW_WORDS` | warning | Very few words |
682
+ | `UNBALANCED_BRACKETS` | warning | Mismatched brackets |
683
+ | `LONG_LINES` | suggestion | Lines over 500 chars |
684
+ | `NO_CLEAR_INSTRUCTION` | suggestion | Missing role or task |
685
+
686
+ ---
687
+
688
+ ## 📄 Parser
689
+
690
+ Parse prompt files in YAML, JSON, Markdown, and plain text formats.
691
+
692
+ ```typescript
693
+ import { parser } from 'prompts.chat';
694
+
695
+ // Auto-detect format
696
+ const prompt = parser.parse(content);
697
+
698
+ // Parse YAML
699
+ const yamlPrompt = parser.parse(`
700
+ name: Code Review
701
+ model: gpt-4
702
+ modelParameters:
703
+ temperature: 0.7
704
+ messages:
705
+ - role: system
706
+ content: You are a code reviewer.
707
+ `, 'yaml');
708
+
709
+ // Parse JSON
710
+ const jsonPrompt = parser.parse(`{
711
+ "name": "Assistant",
712
+ "messages": [{"role": "system", "content": "You are helpful."}]
713
+ }`, 'json');
714
+
715
+ // Parse Markdown with frontmatter
716
+ const mdPrompt = parser.parse(`
717
+ ---
718
+ name: Creative Writer
719
+ model: gpt-4
720
+ ---
721
+ You are a creative writing assistant.
722
+ `, 'markdown');
723
+
724
+ // Parse plain text (becomes system message)
725
+ const textPrompt = parser.parse("You are a helpful assistant.", 'text');
726
+
727
+ // Serialize
728
+ const yaml = parser.toYaml(prompt);
729
+ const json = parser.toJson(prompt, true); // pretty print
730
+
731
+ // Get system message
732
+ const systemPrompt = parser.getSystemPrompt(prompt);
733
+
734
+ // Interpolate variables
735
+ const filled = parser.interpolate(prompt, { name: "John" });
736
+ ```
737
+
738
+ ### ParsedPrompt Structure
739
+
740
+ ```typescript
741
+ interface ParsedPrompt {
742
+ name?: string;
743
+ description?: string;
744
+ model?: string;
745
+ modelParameters?: {
746
+ temperature?: number;
747
+ maxTokens?: number;
748
+ topP?: number;
749
+ frequencyPenalty?: number;
750
+ presencePenalty?: number;
751
+ };
752
+ messages: PromptMessage[];
753
+ variables?: Record<string, {
754
+ description?: string;
755
+ default?: string;
756
+ required?: boolean;
757
+ }>;
758
+ metadata?: Record<string, unknown>;
759
+ }
760
+ ```
761
+
762
+ ---
763
+
764
+ ## Tree-Shakeable Imports
765
+
766
+ Import only what you need for smaller bundles:
767
+
768
+ ```typescript
769
+ // Full namespace imports
770
+ import { variables, similarity, quality, parser } from 'prompts.chat';
771
+
772
+ // Direct builder imports
773
+ import { builder, chat, image, video, audio } from 'prompts.chat';
774
+ import { templates, chatPresets } from 'prompts.chat';
775
+
776
+ // Direct module imports (smallest bundle)
777
+ import { detect, normalize, compile } from 'prompts.chat/variables';
778
+ import { calculate, isDuplicate } from 'prompts.chat/similarity';
779
+ import { check, validate, getSuggestions } from 'prompts.chat/quality';
780
+ import { parse, toYaml, toJson } from 'prompts.chat/parser';
781
+ import { builder, templates } from 'prompts.chat/builder';
782
+ ```
783
+
784
+ ---
785
+
786
+ ## TypeScript Support
787
+
788
+ Full TypeScript support with comprehensive type exports:
789
+
790
+ ```typescript
791
+ import type {
792
+ // Variables
793
+ DetectedVariable,
794
+ VariablePattern,
795
+
796
+ // Builder
797
+ BuiltPrompt,
798
+ PromptVariable,
799
+
800
+ // Chat
801
+ BuiltChatPrompt,
802
+ ChatMessage,
803
+ ChatPersona,
804
+ PersonaTone,
805
+ ReasoningStyle,
806
+
807
+ // Image
808
+ BuiltImagePrompt,
809
+ ImageSubject,
810
+ ImageCamera,
811
+ CameraAngle,
812
+ ShotType,
813
+ LensType,
814
+
815
+ // Video
816
+ BuiltVideoPrompt,
817
+ VideoScene,
818
+ VideoCamera,
819
+
820
+ // Audio
821
+ BuiltAudioPrompt,
822
+ MusicGenre,
823
+ Instrument,
824
+
825
+ // Quality
826
+ QualityResult,
827
+ QualityIssue,
828
+
829
+ // Parser
830
+ ParsedPrompt,
831
+ PromptMessage,
832
+ } from 'prompts.chat';
833
+ ```
834
+
835
+ ---
836
+
837
+ ## Requirements
838
+
839
+ - **Node.js** 18+
840
+ - **TypeScript** 5+ (optional, for type checking)
841
+
842
+ ---
843
+
844
+ ## Testing
845
+
846
+ ```bash
847
+ npm test # Run all tests
848
+ npm run test:watch # Watch mode
849
+ npm run test:coverage # With coverage
850
+ ```
851
+
852
+ ---
853
+
854
+ ## License
855
+
856
+ MIT © [Fatih Kadir Akın](https://github.com/f)