prompts.chat 0.0.1 → 0.0.2

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 +877 -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/dist/index.mjs ADDED
@@ -0,0 +1,3276 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/variables/index.ts
8
+ var variables_exports = {};
9
+ __export(variables_exports, {
10
+ compile: () => compile,
11
+ convertAllVariables: () => convertAllVariables,
12
+ convertToSupportedFormat: () => convertToSupportedFormat,
13
+ detect: () => detect,
14
+ detectVariables: () => detectVariables,
15
+ extractVariables: () => extractVariables,
16
+ getPatternDescription: () => getPatternDescription,
17
+ normalize: () => normalize
18
+ });
19
+ var PATTERNS = [
20
+ // Double bracket: [[name]] or [[ name ]] or [[name: default]]
21
+ {
22
+ pattern: "double_bracket",
23
+ regex: /\[\[\s*([a-zA-Z_][a-zA-Z0-9_\s]*?)(?:\s*:\s*([^\]]*?))?\s*\]\]/g,
24
+ extractName: (m) => m[1].trim(),
25
+ extractDefault: (m) => m[2]?.trim()
26
+ },
27
+ // Double curly: {{name}} or {{ name }} or {{name: default}}
28
+ {
29
+ pattern: "double_curly",
30
+ regex: /\{\{\s*([a-zA-Z_][a-zA-Z0-9_\s]*?)(?:\s*:\s*([^}]*?))?\s*\}\}/g,
31
+ extractName: (m) => m[1].trim(),
32
+ extractDefault: (m) => m[2]?.trim()
33
+ },
34
+ // Our supported format (to exclude from warnings)
35
+ {
36
+ pattern: "dollar_curly",
37
+ regex: /\$\{([a-zA-Z_][a-zA-Z0-9_\s]*?)(?::([^}]*))?\}/g,
38
+ extractName: (m) => m[1].trim()
39
+ },
40
+ // Single bracket with uppercase or placeholder-like: [NAME] or [Your Name]
41
+ {
42
+ pattern: "single_bracket",
43
+ regex: /\[([A-Z][A-Z0-9_\s]*|[A-Za-z][a-zA-Z0-9_]*(?:\s+[A-Za-z][a-zA-Z0-9_]*)*)\]/g,
44
+ extractName: (m) => m[1].trim()
45
+ },
46
+ // Single curly with uppercase: {NAME} or {Your Name}
47
+ {
48
+ pattern: "single_curly",
49
+ regex: /\{([A-Z][A-Z0-9_\s]*|[A-Za-z][a-zA-Z0-9_]*(?:\s+[A-Za-z][a-zA-Z0-9_]*)*)\}/g,
50
+ extractName: (m) => m[1].trim()
51
+ },
52
+ // Angle brackets: <NAME> or <name>
53
+ {
54
+ pattern: "angle_bracket",
55
+ regex: /<([A-Z][A-Z0-9_\s]*|[a-zA-Z_][a-zA-Z0-9_\s]*)>/g,
56
+ extractName: (m) => m[1].trim()
57
+ },
58
+ // Percent signs: %NAME% or %name%
59
+ {
60
+ pattern: "percent",
61
+ regex: /%([a-zA-Z_][a-zA-Z0-9_]*)%/g,
62
+ extractName: (m) => m[1].trim()
63
+ }
64
+ ];
65
+ var FALSE_POSITIVES = /* @__PURE__ */ new Set([
66
+ // HTML/XML common tags
67
+ "div",
68
+ "span",
69
+ "p",
70
+ "a",
71
+ "br",
72
+ "hr",
73
+ "img",
74
+ "input",
75
+ "button",
76
+ "h1",
77
+ "h2",
78
+ "h3",
79
+ "h4",
80
+ "h5",
81
+ "h6",
82
+ "ul",
83
+ "ol",
84
+ "li",
85
+ "table",
86
+ "tr",
87
+ "td",
88
+ "th",
89
+ "thead",
90
+ "tbody",
91
+ "form",
92
+ "label",
93
+ "select",
94
+ "option",
95
+ "textarea",
96
+ "script",
97
+ "style",
98
+ "link",
99
+ "meta",
100
+ "head",
101
+ "body",
102
+ "html",
103
+ "section",
104
+ "article",
105
+ "nav",
106
+ "header",
107
+ "footer",
108
+ "main",
109
+ "aside",
110
+ "figure",
111
+ "figcaption",
112
+ "strong",
113
+ "em",
114
+ "code",
115
+ "pre",
116
+ "blockquote",
117
+ "cite",
118
+ "abbr",
119
+ "address",
120
+ "b",
121
+ "i",
122
+ "u",
123
+ // Common programming constructs
124
+ "if",
125
+ "else",
126
+ "for",
127
+ "while",
128
+ "switch",
129
+ "case",
130
+ "break",
131
+ "return",
132
+ "function",
133
+ "class",
134
+ "const",
135
+ "let",
136
+ "var",
137
+ "import",
138
+ "export",
139
+ "default",
140
+ "try",
141
+ "catch",
142
+ "finally",
143
+ "throw",
144
+ "new",
145
+ "this",
146
+ "null",
147
+ "undefined",
148
+ "true",
149
+ "false",
150
+ "typeof",
151
+ "instanceof",
152
+ // JSON structure keywords (when in context)
153
+ "type",
154
+ "id",
155
+ "key",
156
+ "value",
157
+ "data",
158
+ "items",
159
+ "properties"
160
+ ]);
161
+ function isInsideJsonString(text, index) {
162
+ let inString = false;
163
+ for (let i = 0; i < index; i++) {
164
+ if (text[i] === '"' && (i === 0 || text[i - 1] !== "\\")) {
165
+ inString = !inString;
166
+ }
167
+ }
168
+ return inString;
169
+ }
170
+ function detectVariables(text) {
171
+ const detected = [];
172
+ const seenRanges = [];
173
+ const supportedVars = /* @__PURE__ */ new Set();
174
+ const dollarCurlyPattern = /\$\{([a-zA-Z_][a-zA-Z0-9_\s]*?)(?::([^}]*))?\}/g;
175
+ let match;
176
+ while ((match = dollarCurlyPattern.exec(text)) !== null) {
177
+ seenRanges.push([match.index, match.index + match[0].length]);
178
+ supportedVars.add(match[0]);
179
+ }
180
+ for (const config of PATTERNS) {
181
+ if (config.pattern === "dollar_curly") continue;
182
+ const regex = new RegExp(config.regex.source, config.regex.flags);
183
+ while ((match = regex.exec(text)) !== null) {
184
+ const startIndex = match.index;
185
+ const endIndex = startIndex + match[0].length;
186
+ const overlaps = seenRanges.some(
187
+ ([start, end]) => startIndex >= start && startIndex < end || endIndex > start && endIndex <= end
188
+ );
189
+ if (overlaps) continue;
190
+ const name = config.extractName(match);
191
+ if (FALSE_POSITIVES.has(name.toLowerCase())) continue;
192
+ if (name.length < 2) continue;
193
+ if (config.pattern === "angle_bracket") {
194
+ if (!/^[A-Z]/.test(name) && !name.includes(" ")) continue;
195
+ }
196
+ if ((config.pattern === "single_curly" || config.pattern === "single_bracket") && isInsideJsonString(text, startIndex)) {
197
+ if (!/^[A-Z]/.test(name) && !name.includes(" ")) continue;
198
+ }
199
+ const defaultValue = config.extractDefault?.(match);
200
+ detected.push({
201
+ original: match[0],
202
+ name,
203
+ defaultValue,
204
+ pattern: config.pattern,
205
+ startIndex,
206
+ endIndex
207
+ });
208
+ seenRanges.push([startIndex, endIndex]);
209
+ }
210
+ }
211
+ return detected.sort((a, b) => a.startIndex - b.startIndex).filter(
212
+ (v, i, arr) => i === 0 || v.original !== arr[i - 1].original || v.startIndex !== arr[i - 1].startIndex
213
+ );
214
+ }
215
+ function convertToSupportedFormat(variable) {
216
+ const normalizedName = variable.name.toLowerCase().replace(/\s+/g, "_").replace(/[^a-z0-9_]/g, "");
217
+ if (variable.defaultValue) {
218
+ return `\${${normalizedName}:${variable.defaultValue}}`;
219
+ }
220
+ return `\${${normalizedName}}`;
221
+ }
222
+ function convertAllVariables(text) {
223
+ const detected = detectVariables(text);
224
+ if (detected.length === 0) return text;
225
+ const sorted = [...detected].sort((a, b) => b.startIndex - a.startIndex);
226
+ let result = text;
227
+ for (const variable of sorted) {
228
+ const converted = convertToSupportedFormat(variable);
229
+ result = result.slice(0, variable.startIndex) + converted + result.slice(variable.endIndex);
230
+ }
231
+ return result;
232
+ }
233
+ var normalize = convertAllVariables;
234
+ var detect = detectVariables;
235
+ function getPatternDescription(pattern) {
236
+ switch (pattern) {
237
+ case "double_bracket":
238
+ return "[[...]]";
239
+ case "double_curly":
240
+ return "{{...}}";
241
+ case "single_bracket":
242
+ return "[...]";
243
+ case "single_curly":
244
+ return "{...}";
245
+ case "angle_bracket":
246
+ return "<...>";
247
+ case "percent":
248
+ return "%...%";
249
+ case "dollar_curly":
250
+ return "${...}";
251
+ }
252
+ }
253
+ function extractVariables(text) {
254
+ const regex = /\$\{([a-zA-Z_][a-zA-Z0-9_\s]*?)(?::([^}]*))?\}/g;
255
+ const variables = [];
256
+ let match;
257
+ while ((match = regex.exec(text)) !== null) {
258
+ variables.push({
259
+ name: match[1].trim(),
260
+ defaultValue: match[2]?.trim()
261
+ });
262
+ }
263
+ return variables;
264
+ }
265
+ function compile(template, values, options = {}) {
266
+ const { useDefaults = true } = options;
267
+ return template.replace(
268
+ /\$\{([a-zA-Z_][a-zA-Z0-9_\s]*?)(?::([^}]*))?\}/g,
269
+ (match, name, defaultValue) => {
270
+ const trimmedName = name.trim();
271
+ if (trimmedName in values) {
272
+ return values[trimmedName];
273
+ }
274
+ if (useDefaults && defaultValue !== void 0) {
275
+ return defaultValue.trim();
276
+ }
277
+ return match;
278
+ }
279
+ );
280
+ }
281
+
282
+ // src/similarity/index.ts
283
+ var similarity_exports = {};
284
+ __export(similarity_exports, {
285
+ calculate: () => calculate,
286
+ calculateSimilarity: () => calculateSimilarity,
287
+ deduplicate: () => deduplicate,
288
+ findDuplicates: () => findDuplicates,
289
+ getContentFingerprint: () => getContentFingerprint,
290
+ isDuplicate: () => isDuplicate,
291
+ isSimilarContent: () => isSimilarContent,
292
+ normalizeContent: () => normalizeContent
293
+ });
294
+ function normalizeContent(content) {
295
+ return content.replace(/\$\{[^}]+\}/g, "").replace(/\[[^\]]+\]/g, "").replace(/<[^>]+>/g, "").toLowerCase().replace(/[^\w\s]/g, "").replace(/\s+/g, " ").trim();
296
+ }
297
+ function jaccardSimilarity(str1, str2) {
298
+ const set1 = new Set(str1.split(" ").filter(Boolean));
299
+ const set2 = new Set(str2.split(" ").filter(Boolean));
300
+ if (set1.size === 0 && set2.size === 0) return 1;
301
+ if (set1.size === 0 || set2.size === 0) return 0;
302
+ const intersection = new Set([...set1].filter((x) => set2.has(x)));
303
+ const union = /* @__PURE__ */ new Set([...set1, ...set2]);
304
+ return intersection.size / union.size;
305
+ }
306
+ function ngramSimilarity(str1, str2, n = 3) {
307
+ const getNgrams = (str) => {
308
+ const ngrams = /* @__PURE__ */ new Set();
309
+ const padded = " ".repeat(n - 1) + str + " ".repeat(n - 1);
310
+ for (let i = 0; i <= padded.length - n; i++) {
311
+ ngrams.add(padded.slice(i, i + n));
312
+ }
313
+ return ngrams;
314
+ };
315
+ const ngrams1 = getNgrams(str1);
316
+ const ngrams2 = getNgrams(str2);
317
+ if (ngrams1.size === 0 && ngrams2.size === 0) return 1;
318
+ if (ngrams1.size === 0 || ngrams2.size === 0) return 0;
319
+ const intersection = new Set([...ngrams1].filter((x) => ngrams2.has(x)));
320
+ const union = /* @__PURE__ */ new Set([...ngrams1, ...ngrams2]);
321
+ return intersection.size / union.size;
322
+ }
323
+ function calculateSimilarity(content1, content2) {
324
+ const normalized1 = normalizeContent(content1);
325
+ const normalized2 = normalizeContent(content2);
326
+ if (normalized1 === normalized2) return 1;
327
+ if (!normalized1 || !normalized2) return 0;
328
+ const jaccard = jaccardSimilarity(normalized1, normalized2);
329
+ const ngram = ngramSimilarity(normalized1, normalized2);
330
+ return jaccard * 0.6 + ngram * 0.4;
331
+ }
332
+ var calculate = calculateSimilarity;
333
+ function isSimilarContent(content1, content2, threshold = 0.85) {
334
+ return calculateSimilarity(content1, content2) >= threshold;
335
+ }
336
+ var isDuplicate = isSimilarContent;
337
+ function getContentFingerprint(content) {
338
+ const normalized = normalizeContent(content);
339
+ return normalized.slice(0, 500);
340
+ }
341
+ function findDuplicates(prompts, threshold = 0.85) {
342
+ const groups = [];
343
+ const used = /* @__PURE__ */ new Set();
344
+ for (let i = 0; i < prompts.length; i++) {
345
+ if (used.has(i)) continue;
346
+ const group = [prompts[i]];
347
+ used.add(i);
348
+ for (let j = i + 1; j < prompts.length; j++) {
349
+ if (used.has(j)) continue;
350
+ if (isSimilarContent(prompts[i].content, prompts[j].content, threshold)) {
351
+ group.push(prompts[j]);
352
+ used.add(j);
353
+ }
354
+ }
355
+ if (group.length > 1) {
356
+ groups.push(group);
357
+ }
358
+ }
359
+ return groups;
360
+ }
361
+ function deduplicate(prompts, threshold = 0.85) {
362
+ const result = [];
363
+ for (const prompt of prompts) {
364
+ const isDupe = result.some(
365
+ (existing) => isSimilarContent(existing.content, prompt.content, threshold)
366
+ );
367
+ if (!isDupe) {
368
+ result.push(prompt);
369
+ }
370
+ }
371
+ return result;
372
+ }
373
+
374
+ // src/quality/index.ts
375
+ var quality_exports = {};
376
+ __export(quality_exports, {
377
+ check: () => check,
378
+ getSuggestions: () => getSuggestions,
379
+ isValid: () => isValid,
380
+ validate: () => validate
381
+ });
382
+ var MIN_CHAR_COUNT = 20;
383
+ var MIN_WORD_COUNT = 5;
384
+ var OPTIMAL_MIN_WORDS = 20;
385
+ var OPTIMAL_MAX_WORDS = 2e3;
386
+ function isGibberish(text) {
387
+ if (/(.)\1{4,}/.test(text)) return true;
388
+ const keyboardPatterns = ["qwerty", "asdfgh", "zxcvbn", "qwertz", "azerty"];
389
+ const lower = text.toLowerCase();
390
+ if (keyboardPatterns.some((p) => lower.includes(p))) return true;
391
+ const vowels = (text.match(/[aeiouAEIOU]/g) || []).length;
392
+ const consonants = (text.match(/[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]/g) || []).length;
393
+ if (consonants > 0 && vowels / consonants < 0.1) return true;
394
+ return false;
395
+ }
396
+ function detectPatterns(text) {
397
+ const lower = text.toLowerCase();
398
+ return {
399
+ hasRole: /\b(act as|you are|imagine you|pretend to be|role:|persona:)\b/i.test(text),
400
+ hasTask: /\b(your task|you (will|should|must)|please|help me|i need|i want you to)\b/i.test(text),
401
+ hasConstraints: /\b(do not|don't|never|always|must|should not|avoid|only|limit)\b/i.test(text) || /\b(rule|constraint|requirement|guideline)\b/i.test(lower),
402
+ hasExamples: /\b(example|for instance|such as|e\.g\.|like this)\b/i.test(lower) || /```[\s\S]*```/.test(text)
403
+ };
404
+ }
405
+ function countVariables(text) {
406
+ const patterns = [
407
+ /\$\{[^}]+\}/g,
408
+ // ${var}
409
+ /\{\{[^}]+\}\}/g,
410
+ // {{var}}
411
+ /\[\[[^\]]+\]\]/g,
412
+ // [[var]]
413
+ /\[[A-Z][A-Z0-9_\s]*\]/g
414
+ // [VAR]
415
+ ];
416
+ let count = 0;
417
+ for (const pattern of patterns) {
418
+ const matches = text.match(pattern);
419
+ if (matches) count += matches.length;
420
+ }
421
+ return count;
422
+ }
423
+ function calculateScore(stats, issues) {
424
+ let score = 1;
425
+ const errors = issues.filter((i) => i.type === "error").length;
426
+ const warnings = issues.filter((i) => i.type === "warning").length;
427
+ score -= errors * 0.2;
428
+ score -= warnings * 0.05;
429
+ if (stats.hasRole) score += 0.05;
430
+ if (stats.hasTask) score += 0.05;
431
+ if (stats.hasConstraints) score += 0.03;
432
+ if (stats.hasExamples) score += 0.05;
433
+ if (stats.wordCount < OPTIMAL_MIN_WORDS) {
434
+ score -= 0.1 * (1 - stats.wordCount / OPTIMAL_MIN_WORDS);
435
+ }
436
+ if (stats.wordCount > OPTIMAL_MAX_WORDS) {
437
+ score -= 0.05;
438
+ }
439
+ if (stats.variableCount > 0) {
440
+ score += 0.05;
441
+ }
442
+ return Math.max(0, Math.min(1, score));
443
+ }
444
+ function check(prompt) {
445
+ const issues = [];
446
+ const trimmed = prompt.trim();
447
+ const characterCount = trimmed.length;
448
+ const words = trimmed.split(/\s+/).filter((w) => w.length > 0);
449
+ const wordCount = words.length;
450
+ const sentenceCount = (trimmed.match(/[.!?]+/g) || []).length || 1;
451
+ const variableCount = countVariables(trimmed);
452
+ const patterns = detectPatterns(trimmed);
453
+ if (characterCount === 0) {
454
+ issues.push({
455
+ type: "error",
456
+ code: "EMPTY",
457
+ message: "Prompt is empty"
458
+ });
459
+ } else if (characterCount < MIN_CHAR_COUNT) {
460
+ issues.push({
461
+ type: "error",
462
+ code: "TOO_SHORT",
463
+ message: `Prompt is too short (${characterCount} chars, minimum ${MIN_CHAR_COUNT})`
464
+ });
465
+ }
466
+ if (wordCount > 0 && wordCount < MIN_WORD_COUNT) {
467
+ issues.push({
468
+ type: "warning",
469
+ code: "FEW_WORDS",
470
+ message: `Prompt has very few words (${wordCount} words, recommended ${OPTIMAL_MIN_WORDS}+)`
471
+ });
472
+ }
473
+ if (isGibberish(trimmed)) {
474
+ issues.push({
475
+ type: "error",
476
+ code: "GIBBERISH",
477
+ message: "Prompt appears to contain gibberish or random characters"
478
+ });
479
+ }
480
+ if (!patterns.hasTask && !patterns.hasRole) {
481
+ issues.push({
482
+ type: "suggestion",
483
+ code: "NO_CLEAR_INSTRUCTION",
484
+ message: "Consider adding a clear task or role definition"
485
+ });
486
+ }
487
+ const brackets = [
488
+ { open: "{", close: "}" },
489
+ { open: "[", close: "]" },
490
+ { open: "(", close: ")" }
491
+ ];
492
+ for (const { open, close } of brackets) {
493
+ const openCount = (trimmed.match(new RegExp(`\\${open}`, "g")) || []).length;
494
+ const closeCount = (trimmed.match(new RegExp(`\\${close}`, "g")) || []).length;
495
+ if (openCount !== closeCount) {
496
+ issues.push({
497
+ type: "warning",
498
+ code: "UNBALANCED_BRACKETS",
499
+ message: `Unbalanced ${open}${close} brackets (${openCount} open, ${closeCount} close)`
500
+ });
501
+ }
502
+ }
503
+ const lines = trimmed.split("\n");
504
+ const longLines = lines.filter((l) => l.length > 500);
505
+ if (longLines.length > 0) {
506
+ issues.push({
507
+ type: "suggestion",
508
+ code: "LONG_LINES",
509
+ message: "Some lines are very long. Consider breaking them up for readability."
510
+ });
511
+ }
512
+ const stats = {
513
+ characterCount,
514
+ wordCount,
515
+ sentenceCount,
516
+ variableCount,
517
+ ...patterns
518
+ };
519
+ const score = calculateScore(stats, issues);
520
+ const hasErrors = issues.some((i) => i.type === "error");
521
+ return {
522
+ valid: !hasErrors,
523
+ score,
524
+ issues,
525
+ stats
526
+ };
527
+ }
528
+ function validate(prompt) {
529
+ const result = check(prompt);
530
+ if (!result.valid) {
531
+ const errors = result.issues.filter((i) => i.type === "error").map((i) => i.message).join("; ");
532
+ throw new Error(`Invalid prompt: ${errors}`);
533
+ }
534
+ }
535
+ function isValid(prompt) {
536
+ return check(prompt).valid;
537
+ }
538
+ function getSuggestions(prompt) {
539
+ const result = check(prompt);
540
+ const suggestions = [];
541
+ suggestions.push(
542
+ ...result.issues.filter((i) => i.type === "suggestion" || i.type === "warning").map((i) => i.message)
543
+ );
544
+ if (!result.stats.hasRole) {
545
+ suggestions.push('Add a role definition (e.g., "Act as a...")');
546
+ }
547
+ if (!result.stats.hasConstraints && result.stats.wordCount > 50) {
548
+ suggestions.push("Consider adding constraints or rules for better control");
549
+ }
550
+ if (!result.stats.hasExamples && result.stats.wordCount > 100) {
551
+ suggestions.push("Adding examples can improve output quality");
552
+ }
553
+ if (result.stats.variableCount === 0 && result.stats.wordCount > 30) {
554
+ suggestions.push("Consider adding variables (${var}) to make the prompt reusable");
555
+ }
556
+ return suggestions;
557
+ }
558
+
559
+ // src/parser/index.ts
560
+ var parser_exports = {};
561
+ __export(parser_exports, {
562
+ getSystemPrompt: () => getSystemPrompt,
563
+ interpolate: () => interpolate,
564
+ parse: () => parse,
565
+ toJson: () => toJson,
566
+ toYaml: () => toYaml
567
+ });
568
+ function parseSimpleYaml(content) {
569
+ const result = {};
570
+ const lines = content.split("\n");
571
+ let currentKey = null;
572
+ let currentValue = null;
573
+ let inArray = false;
574
+ let inMultiline = false;
575
+ let multilineContent = "";
576
+ let arrayItems = [];
577
+ let indent = 0;
578
+ for (let i = 0; i < lines.length; i++) {
579
+ const line = lines[i];
580
+ const trimmed = line.trim();
581
+ if (!trimmed || trimmed.startsWith("#")) {
582
+ if (inMultiline) {
583
+ multilineContent += "\n";
584
+ }
585
+ continue;
586
+ }
587
+ if (inMultiline) {
588
+ const lineIndent = line.search(/\S/);
589
+ if (lineIndent > indent) {
590
+ multilineContent += (multilineContent ? "\n" : "") + line.slice(indent + 2);
591
+ continue;
592
+ } else {
593
+ if (inArray && currentKey) {
594
+ const lastItem = arrayItems[arrayItems.length - 1];
595
+ if (lastItem && typeof lastItem === "object") {
596
+ const keys = Object.keys(lastItem);
597
+ const lastKey = keys[keys.length - 1];
598
+ lastItem[lastKey] = multilineContent.trim();
599
+ }
600
+ } else if (currentKey) {
601
+ result[currentKey] = multilineContent.trim();
602
+ }
603
+ inMultiline = false;
604
+ multilineContent = "";
605
+ }
606
+ }
607
+ if (trimmed.startsWith("- ")) {
608
+ if (!inArray && currentKey) {
609
+ inArray = true;
610
+ arrayItems = [];
611
+ }
612
+ const itemContent = trimmed.slice(2);
613
+ const kvMatch = itemContent.match(/^(\w+):\s*(.*)$/);
614
+ if (kvMatch) {
615
+ const obj = {};
616
+ obj[kvMatch[1]] = kvMatch[2] === "|" ? "" : kvMatch[2] || "";
617
+ if (kvMatch[2] === "|") {
618
+ inMultiline = true;
619
+ indent = line.search(/\S/);
620
+ multilineContent = "";
621
+ }
622
+ arrayItems.push(obj);
623
+ } else {
624
+ arrayItems.push(itemContent);
625
+ }
626
+ continue;
627
+ }
628
+ if (inArray && line.startsWith(" ")) {
629
+ const propMatch = trimmed.match(/^(\w+):\s*(.*)$/);
630
+ if (propMatch && arrayItems.length > 0) {
631
+ const lastItem = arrayItems[arrayItems.length - 1];
632
+ if (typeof lastItem === "object" && lastItem !== null) {
633
+ lastItem[propMatch[1]] = propMatch[2] === "|" ? "" : propMatch[2] || "";
634
+ if (propMatch[2] === "|") {
635
+ inMultiline = true;
636
+ indent = line.search(/\S/);
637
+ multilineContent = "";
638
+ }
639
+ }
640
+ }
641
+ continue;
642
+ }
643
+ if (inArray && !line.startsWith(" ") && !line.startsWith(" ")) {
644
+ if (currentKey) {
645
+ result[currentKey] = arrayItems;
646
+ }
647
+ inArray = false;
648
+ arrayItems = [];
649
+ }
650
+ const match = trimmed.match(/^(\w+):\s*(.*)$/);
651
+ if (match) {
652
+ currentKey = match[1];
653
+ const value = match[2];
654
+ if (value === "" || value === "|" || value === ">") {
655
+ if (value === "|" || value === ">") {
656
+ inMultiline = true;
657
+ indent = line.search(/\S/);
658
+ multilineContent = "";
659
+ }
660
+ } else if (value.startsWith('"') && value.endsWith('"')) {
661
+ result[currentKey] = value.slice(1, -1);
662
+ } else if (value.startsWith("'") && value.endsWith("'")) {
663
+ result[currentKey] = value.slice(1, -1);
664
+ } else if (value === "true") {
665
+ result[currentKey] = true;
666
+ } else if (value === "false") {
667
+ result[currentKey] = false;
668
+ } else if (!isNaN(Number(value))) {
669
+ result[currentKey] = Number(value);
670
+ } else {
671
+ result[currentKey] = value;
672
+ }
673
+ }
674
+ }
675
+ if (inArray && currentKey) {
676
+ result[currentKey] = arrayItems;
677
+ }
678
+ if (inMultiline && currentKey) {
679
+ result[currentKey] = multilineContent.trim();
680
+ }
681
+ return result;
682
+ }
683
+ function parseJson(content) {
684
+ return JSON.parse(content);
685
+ }
686
+ function parseMarkdown(content) {
687
+ const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
688
+ if (frontmatterMatch) {
689
+ const frontmatter = parseSimpleYaml(frontmatterMatch[1]);
690
+ const body = frontmatterMatch[2].trim();
691
+ return {
692
+ ...frontmatter,
693
+ messages: [{ role: "system", content: body }]
694
+ };
695
+ }
696
+ return {
697
+ messages: [{ role: "system", content: content.trim() }]
698
+ };
699
+ }
700
+ function normalize2(data) {
701
+ const messages = [];
702
+ if (Array.isArray(data.messages)) {
703
+ for (const msg of data.messages) {
704
+ if (typeof msg === "object" && msg !== null) {
705
+ const m = msg;
706
+ messages.push({
707
+ role: m.role || "user",
708
+ content: String(m.content || "")
709
+ });
710
+ }
711
+ }
712
+ }
713
+ if (messages.length === 0 && typeof data.content === "string") {
714
+ messages.push({ role: "system", content: data.content });
715
+ }
716
+ if (messages.length === 0 && typeof data.prompt === "string") {
717
+ messages.push({ role: "system", content: data.prompt });
718
+ }
719
+ return {
720
+ name: data.name,
721
+ description: data.description,
722
+ model: data.model,
723
+ modelParameters: data.modelParameters,
724
+ messages,
725
+ variables: data.variables,
726
+ metadata: data.metadata
727
+ };
728
+ }
729
+ function parse(content, format) {
730
+ const trimmed = content.trim();
731
+ if (!format) {
732
+ if (trimmed.startsWith("{")) {
733
+ format = "json";
734
+ } else if (trimmed.startsWith("---")) {
735
+ format = "markdown";
736
+ } else if (trimmed.includes(":") && (trimmed.includes("\n ") || trimmed.includes("\n-"))) {
737
+ format = "yaml";
738
+ } else {
739
+ format = "text";
740
+ }
741
+ }
742
+ let data;
743
+ switch (format) {
744
+ case "json":
745
+ data = parseJson(trimmed);
746
+ break;
747
+ case "yaml":
748
+ data = parseSimpleYaml(trimmed);
749
+ break;
750
+ case "markdown":
751
+ data = parseMarkdown(trimmed);
752
+ break;
753
+ case "text":
754
+ default:
755
+ data = { messages: [{ role: "system", content: trimmed }] };
756
+ break;
757
+ }
758
+ return normalize2(data);
759
+ }
760
+ function toYaml(prompt) {
761
+ const lines = [];
762
+ if (prompt.name) {
763
+ lines.push(`name: ${prompt.name}`);
764
+ }
765
+ if (prompt.description) {
766
+ lines.push(`description: ${prompt.description}`);
767
+ }
768
+ if (prompt.model) {
769
+ lines.push(`model: ${prompt.model}`);
770
+ }
771
+ if (prompt.modelParameters) {
772
+ lines.push("modelParameters:");
773
+ for (const [key, value] of Object.entries(prompt.modelParameters)) {
774
+ if (value !== void 0) {
775
+ lines.push(` ${key}: ${value}`);
776
+ }
777
+ }
778
+ }
779
+ if (prompt.messages.length > 0) {
780
+ lines.push("messages:");
781
+ for (const msg of prompt.messages) {
782
+ lines.push(` - role: ${msg.role}`);
783
+ if (msg.content.includes("\n")) {
784
+ lines.push(" content: |");
785
+ for (const line of msg.content.split("\n")) {
786
+ lines.push(` ${line}`);
787
+ }
788
+ } else {
789
+ lines.push(` content: "${msg.content.replace(/"/g, '\\"')}"`);
790
+ }
791
+ }
792
+ }
793
+ return lines.join("\n");
794
+ }
795
+ function toJson(prompt, pretty = true) {
796
+ return JSON.stringify(prompt, null, pretty ? 2 : 0);
797
+ }
798
+ function getSystemPrompt(prompt) {
799
+ const systemMessage = prompt.messages.find((m) => m.role === "system");
800
+ return systemMessage?.content || "";
801
+ }
802
+ function interpolate(prompt, values) {
803
+ const interpolateString = (str) => {
804
+ return str.replace(/\{\{(\w+)\}\}/g, (match, key) => {
805
+ if (key in values) return values[key];
806
+ if (prompt.variables?.[key]?.default) return prompt.variables[key].default;
807
+ return match;
808
+ });
809
+ };
810
+ return {
811
+ ...prompt,
812
+ messages: prompt.messages.map((msg) => ({
813
+ ...msg,
814
+ content: interpolateString(msg.content)
815
+ }))
816
+ };
817
+ }
818
+
819
+ // src/builder/media.ts
820
+ var ImagePromptBuilder = class {
821
+ constructor() {
822
+ this._negative = [];
823
+ this._custom = [];
824
+ }
825
+ // --- Subject Methods ---
826
+ subject(main) {
827
+ if (typeof main === "string") {
828
+ this._subject = { ...this._subject || {}, main };
829
+ } else {
830
+ this._subject = { ...this._subject || {}, ...main };
831
+ }
832
+ return this;
833
+ }
834
+ subjectDetails(details) {
835
+ this._subject = { ...this._subject || { main: "" }, details };
836
+ return this;
837
+ }
838
+ expression(expression) {
839
+ this._subject = { ...this._subject || { main: "" }, expression };
840
+ return this;
841
+ }
842
+ pose(pose) {
843
+ this._subject = { ...this._subject || { main: "" }, pose };
844
+ return this;
845
+ }
846
+ action(action) {
847
+ this._subject = { ...this._subject || { main: "" }, action };
848
+ return this;
849
+ }
850
+ clothing(clothing) {
851
+ this._subject = { ...this._subject || { main: "" }, clothing };
852
+ return this;
853
+ }
854
+ accessories(accessories) {
855
+ this._subject = { ...this._subject || { main: "" }, accessories };
856
+ return this;
857
+ }
858
+ subjectCount(count) {
859
+ this._subject = { ...this._subject || { main: "" }, count };
860
+ return this;
861
+ }
862
+ // --- Camera Methods ---
863
+ camera(settings) {
864
+ this._camera = { ...this._camera || {}, ...settings };
865
+ return this;
866
+ }
867
+ angle(angle) {
868
+ this._camera = { ...this._camera || {}, angle };
869
+ return this;
870
+ }
871
+ shot(shot) {
872
+ this._camera = { ...this._camera || {}, shot };
873
+ return this;
874
+ }
875
+ lens(lens) {
876
+ this._camera = { ...this._camera || {}, lens };
877
+ return this;
878
+ }
879
+ focus(focus) {
880
+ this._camera = { ...this._camera || {}, focus };
881
+ return this;
882
+ }
883
+ aperture(aperture) {
884
+ this._camera = { ...this._camera || {}, aperture };
885
+ return this;
886
+ }
887
+ filmStock(filmStock) {
888
+ this._camera = { ...this._camera || {}, filmStock };
889
+ return this;
890
+ }
891
+ filmFormat(format) {
892
+ this._camera = { ...this._camera || {}, filmFormat: format };
893
+ return this;
894
+ }
895
+ cameraBrand(brand) {
896
+ this._camera = { ...this._camera || {}, brand };
897
+ return this;
898
+ }
899
+ cameraModel(model) {
900
+ this._camera = { ...this._camera || {}, model };
901
+ return this;
902
+ }
903
+ sensor(sensor) {
904
+ this._camera = { ...this._camera || {}, sensor };
905
+ return this;
906
+ }
907
+ lensModel(model) {
908
+ this._camera = { ...this._camera || {}, lensModel: model };
909
+ return this;
910
+ }
911
+ lensBrand(brand) {
912
+ this._camera = { ...this._camera || {}, lensBrand: brand };
913
+ return this;
914
+ }
915
+ focalLength(length) {
916
+ this._camera = { ...this._camera || {}, focalLength: length };
917
+ return this;
918
+ }
919
+ bokeh(style) {
920
+ this._camera = { ...this._camera || {}, bokeh: style };
921
+ return this;
922
+ }
923
+ filter(filter) {
924
+ this._camera = { ...this._camera || {}, filter };
925
+ return this;
926
+ }
927
+ iso(iso) {
928
+ this._camera = { ...this._camera || {}, iso };
929
+ return this;
930
+ }
931
+ shutterSpeed(speed) {
932
+ this._camera = { ...this._camera || {}, shutterSpeed: speed };
933
+ return this;
934
+ }
935
+ whiteBalance(wb) {
936
+ this._camera = { ...this._camera || {}, whiteBalance: wb };
937
+ return this;
938
+ }
939
+ colorProfile(profile) {
940
+ this._camera = { ...this._camera || {}, colorProfile: profile };
941
+ return this;
942
+ }
943
+ // --- Lighting Methods ---
944
+ lighting(settings) {
945
+ this._lighting = { ...this._lighting || {}, ...settings };
946
+ return this;
947
+ }
948
+ lightingType(type) {
949
+ this._lighting = { ...this._lighting || {}, type };
950
+ return this;
951
+ }
952
+ timeOfDay(time) {
953
+ this._lighting = { ...this._lighting || {}, time };
954
+ return this;
955
+ }
956
+ weather(weather) {
957
+ this._lighting = { ...this._lighting || {}, weather };
958
+ return this;
959
+ }
960
+ lightDirection(direction) {
961
+ this._lighting = { ...this._lighting || {}, direction };
962
+ return this;
963
+ }
964
+ lightIntensity(intensity) {
965
+ this._lighting = { ...this._lighting || {}, intensity };
966
+ return this;
967
+ }
968
+ // --- Composition Methods ---
969
+ composition(settings) {
970
+ this._composition = { ...this._composition || {}, ...settings };
971
+ return this;
972
+ }
973
+ ruleOfThirds() {
974
+ this._composition = { ...this._composition || {}, ruleOfThirds: true };
975
+ return this;
976
+ }
977
+ goldenRatio() {
978
+ this._composition = { ...this._composition || {}, goldenRatio: true };
979
+ return this;
980
+ }
981
+ symmetry(type) {
982
+ this._composition = { ...this._composition || {}, symmetry: type };
983
+ return this;
984
+ }
985
+ foreground(fg) {
986
+ this._composition = { ...this._composition || {}, foreground: fg };
987
+ return this;
988
+ }
989
+ midground(mg) {
990
+ this._composition = { ...this._composition || {}, midground: mg };
991
+ return this;
992
+ }
993
+ background(bg) {
994
+ this._composition = { ...this._composition || {}, background: bg };
995
+ return this;
996
+ }
997
+ // --- Environment Methods ---
998
+ environment(setting) {
999
+ if (typeof setting === "string") {
1000
+ this._environment = { ...this._environment || { setting: "" }, setting };
1001
+ } else {
1002
+ this._environment = { ...this._environment || { setting: "" }, ...setting };
1003
+ }
1004
+ return this;
1005
+ }
1006
+ location(location) {
1007
+ this._environment = { ...this._environment || { setting: "" }, location };
1008
+ return this;
1009
+ }
1010
+ props(props) {
1011
+ this._environment = { ...this._environment || { setting: "" }, props };
1012
+ return this;
1013
+ }
1014
+ atmosphere(atmosphere) {
1015
+ this._environment = { ...this._environment || { setting: "" }, atmosphere };
1016
+ return this;
1017
+ }
1018
+ season(season) {
1019
+ this._environment = { ...this._environment || { setting: "" }, season };
1020
+ return this;
1021
+ }
1022
+ // --- Style Methods ---
1023
+ style(settings) {
1024
+ this._style = { ...this._style || {}, ...settings };
1025
+ return this;
1026
+ }
1027
+ medium(medium) {
1028
+ this._style = { ...this._style || {}, medium };
1029
+ return this;
1030
+ }
1031
+ artist(artist) {
1032
+ this._style = { ...this._style || {}, artist };
1033
+ return this;
1034
+ }
1035
+ influence(influences) {
1036
+ this._style = { ...this._style || {}, influence: influences };
1037
+ return this;
1038
+ }
1039
+ // --- Color Methods ---
1040
+ color(settings) {
1041
+ this._color = { ...this._color || {}, ...settings };
1042
+ return this;
1043
+ }
1044
+ palette(palette) {
1045
+ this._color = { ...this._color || {}, palette };
1046
+ return this;
1047
+ }
1048
+ primaryColors(colors) {
1049
+ this._color = { ...this._color || {}, primary: colors };
1050
+ return this;
1051
+ }
1052
+ accentColors(colors) {
1053
+ this._color = { ...this._color || {}, accent: colors };
1054
+ return this;
1055
+ }
1056
+ colorGrade(grade) {
1057
+ this._color = { ...this._color || {}, grade };
1058
+ return this;
1059
+ }
1060
+ // --- Technical Methods ---
1061
+ technical(settings) {
1062
+ this._technical = { ...this._technical || {}, ...settings };
1063
+ return this;
1064
+ }
1065
+ aspectRatio(ratio) {
1066
+ this._technical = { ...this._technical || {}, aspectRatio: ratio };
1067
+ return this;
1068
+ }
1069
+ resolution(resolution) {
1070
+ this._technical = { ...this._technical || {}, resolution };
1071
+ return this;
1072
+ }
1073
+ quality(quality) {
1074
+ this._technical = { ...this._technical || {}, quality };
1075
+ return this;
1076
+ }
1077
+ // --- Mood & Misc ---
1078
+ mood(mood) {
1079
+ this._mood = mood;
1080
+ return this;
1081
+ }
1082
+ negative(items) {
1083
+ this._negative = [...this._negative, ...items];
1084
+ return this;
1085
+ }
1086
+ custom(text) {
1087
+ this._custom.push(text);
1088
+ return this;
1089
+ }
1090
+ // --- Build Methods ---
1091
+ buildPromptText() {
1092
+ const parts = [];
1093
+ if (this._subject) {
1094
+ let subjectText = this._subject.main;
1095
+ if (this._subject.count && this._subject.count !== "single") {
1096
+ subjectText = `${this._subject.count} ${subjectText}`;
1097
+ }
1098
+ if (this._subject.expression) subjectText += `, ${this._subject.expression} expression`;
1099
+ if (this._subject.pose) subjectText += `, ${this._subject.pose}`;
1100
+ if (this._subject.action) subjectText += `, ${this._subject.action}`;
1101
+ if (this._subject.clothing) subjectText += `, wearing ${this._subject.clothing}`;
1102
+ if (this._subject.accessories?.length) subjectText += `, with ${this._subject.accessories.join(", ")}`;
1103
+ if (this._subject.details?.length) subjectText += `, ${this._subject.details.join(", ")}`;
1104
+ parts.push(subjectText);
1105
+ }
1106
+ if (this._environment) {
1107
+ let envText = this._environment.setting;
1108
+ if (this._environment.location) envText += ` in ${this._environment.location}`;
1109
+ if (this._environment.atmosphere) envText += `, ${this._environment.atmosphere} atmosphere`;
1110
+ if (this._environment.season) envText += `, ${this._environment.season}`;
1111
+ if (this._environment.props?.length) envText += `, with ${this._environment.props.join(", ")}`;
1112
+ parts.push(envText);
1113
+ }
1114
+ if (this._composition) {
1115
+ const compParts = [];
1116
+ if (this._composition.foreground) compParts.push(`foreground: ${this._composition.foreground}`);
1117
+ if (this._composition.midground) compParts.push(`midground: ${this._composition.midground}`);
1118
+ if (this._composition.background) compParts.push(`background: ${this._composition.background}`);
1119
+ if (this._composition.ruleOfThirds) compParts.push("rule of thirds composition");
1120
+ if (this._composition.goldenRatio) compParts.push("golden ratio composition");
1121
+ if (this._composition.symmetry && this._composition.symmetry !== "none") {
1122
+ compParts.push(`${this._composition.symmetry} symmetry`);
1123
+ }
1124
+ if (compParts.length) parts.push(compParts.join(", "));
1125
+ }
1126
+ if (this._camera) {
1127
+ const camParts = [];
1128
+ if (this._camera.shot) camParts.push(`${this._camera.shot} shot`);
1129
+ if (this._camera.angle) camParts.push(`${this._camera.angle}`);
1130
+ if (this._camera.lens) camParts.push(`${this._camera.lens} lens`);
1131
+ if (this._camera.focus) camParts.push(`${this._camera.focus} depth of field`);
1132
+ if (this._camera.aperture) camParts.push(`f/${this._camera.aperture}`);
1133
+ if (this._camera.filmStock) camParts.push(`shot on ${this._camera.filmStock}`);
1134
+ if (this._camera.brand) camParts.push(`${this._camera.brand}`);
1135
+ if (camParts.length) parts.push(camParts.join(", "));
1136
+ }
1137
+ if (this._lighting) {
1138
+ const lightParts = [];
1139
+ if (this._lighting.type) {
1140
+ const types = Array.isArray(this._lighting.type) ? this._lighting.type : [this._lighting.type];
1141
+ lightParts.push(`${types.join(" and ")} lighting`);
1142
+ }
1143
+ if (this._lighting.time) lightParts.push(this._lighting.time);
1144
+ if (this._lighting.weather) lightParts.push(`${this._lighting.weather} weather`);
1145
+ if (this._lighting.direction) lightParts.push(`light from ${this._lighting.direction}`);
1146
+ if (this._lighting.intensity) lightParts.push(`${this._lighting.intensity} light`);
1147
+ if (lightParts.length) parts.push(lightParts.join(", "));
1148
+ }
1149
+ if (this._style) {
1150
+ const styleParts = [];
1151
+ if (this._style.medium) {
1152
+ const mediums = Array.isArray(this._style.medium) ? this._style.medium : [this._style.medium];
1153
+ styleParts.push(mediums.join(", "));
1154
+ }
1155
+ if (this._style.artist) {
1156
+ const artists = Array.isArray(this._style.artist) ? this._style.artist : [this._style.artist];
1157
+ styleParts.push(`in the style of ${artists.join(" and ")}`);
1158
+ }
1159
+ if (this._style.era) styleParts.push(this._style.era);
1160
+ if (this._style.influence?.length) styleParts.push(`influenced by ${this._style.influence.join(", ")}`);
1161
+ if (this._style.quality?.length) styleParts.push(this._style.quality.join(", "));
1162
+ if (styleParts.length) parts.push(styleParts.join(", "));
1163
+ }
1164
+ if (this._color) {
1165
+ const colorParts = [];
1166
+ if (this._color.palette) {
1167
+ const palettes = Array.isArray(this._color.palette) ? this._color.palette : [this._color.palette];
1168
+ colorParts.push(`${palettes.join(" and ")} color palette`);
1169
+ }
1170
+ if (this._color.primary?.length) colorParts.push(`primary colors: ${this._color.primary.join(", ")}`);
1171
+ if (this._color.accent?.length) colorParts.push(`accent colors: ${this._color.accent.join(", ")}`);
1172
+ if (this._color.grade) colorParts.push(`${this._color.grade} color grade`);
1173
+ if (this._color.temperature) colorParts.push(`${this._color.temperature} tones`);
1174
+ if (colorParts.length) parts.push(colorParts.join(", "));
1175
+ }
1176
+ if (this._mood) {
1177
+ const moods = Array.isArray(this._mood) ? this._mood : [this._mood];
1178
+ parts.push(`${moods.join(", ")} mood`);
1179
+ }
1180
+ if (this._technical) {
1181
+ const techParts = [];
1182
+ if (this._technical.quality) techParts.push(`${this._technical.quality} quality`);
1183
+ if (this._technical.detail) techParts.push(`${this._technical.detail} detail`);
1184
+ if (this._technical.resolution) techParts.push(this._technical.resolution);
1185
+ if (techParts.length) parts.push(techParts.join(", "));
1186
+ }
1187
+ if (this._custom.length) {
1188
+ parts.push(this._custom.join(", "));
1189
+ }
1190
+ let prompt = parts.join(", ");
1191
+ if (this._negative.length) {
1192
+ prompt += ` --no ${this._negative.join(", ")}`;
1193
+ }
1194
+ if (this._technical?.aspectRatio) {
1195
+ prompt += ` --ar ${this._technical.aspectRatio}`;
1196
+ }
1197
+ return prompt;
1198
+ }
1199
+ build() {
1200
+ return {
1201
+ prompt: this.buildPromptText(),
1202
+ structure: {
1203
+ subject: this._subject,
1204
+ camera: this._camera,
1205
+ lighting: this._lighting,
1206
+ composition: this._composition,
1207
+ style: this._style,
1208
+ color: this._color,
1209
+ environment: this._environment,
1210
+ technical: this._technical,
1211
+ mood: this._mood,
1212
+ negative: this._negative.length ? this._negative : void 0
1213
+ }
1214
+ };
1215
+ }
1216
+ toString() {
1217
+ return this.build().prompt;
1218
+ }
1219
+ toJSON() {
1220
+ return JSON.stringify(this.build().structure, null, 2);
1221
+ }
1222
+ toYAML() {
1223
+ return objectToYaml(this.build().structure);
1224
+ }
1225
+ toMarkdown() {
1226
+ const built = this.build();
1227
+ const sections = ["# Image Prompt\n"];
1228
+ sections.push("## Prompt\n```\n" + built.prompt + "\n```\n");
1229
+ if (built.structure.subject) {
1230
+ sections.push("## Subject\n" + objectToMarkdownList(built.structure.subject));
1231
+ }
1232
+ if (built.structure.environment) {
1233
+ sections.push("## Environment\n" + objectToMarkdownList(built.structure.environment));
1234
+ }
1235
+ if (built.structure.camera) {
1236
+ sections.push("## Camera\n" + objectToMarkdownList(built.structure.camera));
1237
+ }
1238
+ if (built.structure.lighting) {
1239
+ sections.push("## Lighting\n" + objectToMarkdownList(built.structure.lighting));
1240
+ }
1241
+ if (built.structure.composition) {
1242
+ sections.push("## Composition\n" + objectToMarkdownList(built.structure.composition));
1243
+ }
1244
+ if (built.structure.style) {
1245
+ sections.push("## Style\n" + objectToMarkdownList(built.structure.style));
1246
+ }
1247
+ if (built.structure.color) {
1248
+ sections.push("## Color\n" + objectToMarkdownList(built.structure.color));
1249
+ }
1250
+ if (built.structure.technical) {
1251
+ sections.push("## Technical\n" + objectToMarkdownList(built.structure.technical));
1252
+ }
1253
+ return sections.join("\n");
1254
+ }
1255
+ format(fmt) {
1256
+ switch (fmt) {
1257
+ case "json":
1258
+ return this.toJSON();
1259
+ case "yaml":
1260
+ return this.toYAML();
1261
+ case "markdown":
1262
+ return this.toMarkdown();
1263
+ default:
1264
+ return this.toString();
1265
+ }
1266
+ }
1267
+ };
1268
+ function objectToYaml(obj, indent = 0) {
1269
+ const spaces = " ".repeat(indent);
1270
+ const lines = [];
1271
+ for (const [key, value] of Object.entries(obj)) {
1272
+ if (value === void 0 || value === null) continue;
1273
+ if (Array.isArray(value)) {
1274
+ if (value.length === 0) continue;
1275
+ lines.push(`${spaces}${key}:`);
1276
+ for (const item of value) {
1277
+ if (typeof item === "object") {
1278
+ lines.push(`${spaces} -`);
1279
+ lines.push(objectToYaml(item, indent + 2).replace(/^/gm, " "));
1280
+ } else {
1281
+ lines.push(`${spaces} - ${item}`);
1282
+ }
1283
+ }
1284
+ } else if (typeof value === "object") {
1285
+ lines.push(`${spaces}${key}:`);
1286
+ lines.push(objectToYaml(value, indent + 1));
1287
+ } else {
1288
+ lines.push(`${spaces}${key}: ${value}`);
1289
+ }
1290
+ }
1291
+ return lines.join("\n");
1292
+ }
1293
+ function objectToMarkdownList(obj, indent = 0) {
1294
+ const spaces = " ".repeat(indent);
1295
+ const lines = [];
1296
+ for (const [key, value] of Object.entries(obj)) {
1297
+ if (value === void 0 || value === null) continue;
1298
+ if (Array.isArray(value)) {
1299
+ lines.push(`${spaces}- **${key}:** ${value.join(", ")}`);
1300
+ } else if (typeof value === "object") {
1301
+ lines.push(`${spaces}- **${key}:**`);
1302
+ lines.push(objectToMarkdownList(value, indent + 1));
1303
+ } else {
1304
+ lines.push(`${spaces}- **${key}:** ${value}`);
1305
+ }
1306
+ }
1307
+ return lines.join("\n");
1308
+ }
1309
+ function image() {
1310
+ return new ImagePromptBuilder();
1311
+ }
1312
+
1313
+ // src/builder/video.ts
1314
+ var VideoPromptBuilder = class {
1315
+ constructor() {
1316
+ this._actions = [];
1317
+ this._shots = [];
1318
+ this._transitions = [];
1319
+ this._custom = [];
1320
+ }
1321
+ // --- Scene Methods ---
1322
+ scene(description) {
1323
+ if (typeof description === "string") {
1324
+ this._scene = { ...this._scene || { description: "" }, description };
1325
+ } else {
1326
+ this._scene = { ...this._scene || { description: "" }, ...description };
1327
+ }
1328
+ return this;
1329
+ }
1330
+ setting(setting) {
1331
+ this._scene = { ...this._scene || { description: "" }, setting };
1332
+ return this;
1333
+ }
1334
+ // --- Subject Methods ---
1335
+ subject(main) {
1336
+ if (typeof main === "string") {
1337
+ this._subject = { ...this._subject || { main: "" }, main };
1338
+ } else {
1339
+ this._subject = { ...this._subject || { main: "" }, ...main };
1340
+ }
1341
+ return this;
1342
+ }
1343
+ appearance(appearance) {
1344
+ this._subject = { ...this._subject || { main: "" }, appearance };
1345
+ return this;
1346
+ }
1347
+ clothing(clothing) {
1348
+ this._subject = { ...this._subject || { main: "" }, clothing };
1349
+ return this;
1350
+ }
1351
+ // --- Camera Methods ---
1352
+ camera(settings) {
1353
+ this._camera = { ...this._camera || {}, ...settings };
1354
+ return this;
1355
+ }
1356
+ shot(shot) {
1357
+ this._camera = { ...this._camera || {}, shot };
1358
+ return this;
1359
+ }
1360
+ angle(angle) {
1361
+ this._camera = { ...this._camera || {}, angle };
1362
+ return this;
1363
+ }
1364
+ movement(movement) {
1365
+ this._camera = { ...this._camera || {}, movement };
1366
+ return this;
1367
+ }
1368
+ lens(lens) {
1369
+ this._camera = { ...this._camera || {}, lens };
1370
+ return this;
1371
+ }
1372
+ platform(platform) {
1373
+ this._camera = { ...this._camera || {}, platform };
1374
+ return this;
1375
+ }
1376
+ cameraSpeed(speed) {
1377
+ this._camera = { ...this._camera || {}, movementSpeed: speed };
1378
+ return this;
1379
+ }
1380
+ movementDirection(direction) {
1381
+ this._camera = { ...this._camera || {}, movementDirection: direction };
1382
+ return this;
1383
+ }
1384
+ rig(rig) {
1385
+ this._camera = { ...this._camera || {}, rig };
1386
+ return this;
1387
+ }
1388
+ gimbal(gimbal) {
1389
+ this._camera = { ...this._camera || {}, gimbal };
1390
+ return this;
1391
+ }
1392
+ cameraBrand(brand) {
1393
+ this._camera = { ...this._camera || {}, brand };
1394
+ return this;
1395
+ }
1396
+ cameraModel(model) {
1397
+ this._camera = { ...this._camera || {}, model };
1398
+ return this;
1399
+ }
1400
+ sensor(sensor) {
1401
+ this._camera = { ...this._camera || {}, sensor };
1402
+ return this;
1403
+ }
1404
+ lensModel(model) {
1405
+ this._camera = { ...this._camera || {}, lensModel: model };
1406
+ return this;
1407
+ }
1408
+ lensBrand(brand) {
1409
+ this._camera = { ...this._camera || {}, lensBrand: brand };
1410
+ return this;
1411
+ }
1412
+ focalLength(length) {
1413
+ this._camera = { ...this._camera || {}, focalLength: length };
1414
+ return this;
1415
+ }
1416
+ anamorphic(ratio) {
1417
+ this._camera = { ...this._camera || {}, anamorphic: true, anamorphicRatio: ratio };
1418
+ return this;
1419
+ }
1420
+ aperture(aperture) {
1421
+ this._camera = { ...this._camera || {}, aperture };
1422
+ return this;
1423
+ }
1424
+ frameRate(fps) {
1425
+ this._camera = { ...this._camera || {}, frameRate: fps };
1426
+ return this;
1427
+ }
1428
+ slowMotion(enabled = true) {
1429
+ this._camera = { ...this._camera || {}, slowMotion: enabled };
1430
+ return this;
1431
+ }
1432
+ shutterAngle(angle) {
1433
+ this._camera = { ...this._camera || {}, shutterAngle: angle };
1434
+ return this;
1435
+ }
1436
+ filter(filter) {
1437
+ this._camera = { ...this._camera || {}, filter };
1438
+ return this;
1439
+ }
1440
+ filmStock(stock) {
1441
+ this._camera = { ...this._camera || {}, filmStock: stock };
1442
+ return this;
1443
+ }
1444
+ filmGrain(grain) {
1445
+ this._camera = { ...this._camera || {}, filmGrain: grain };
1446
+ return this;
1447
+ }
1448
+ halation(enabled = true) {
1449
+ this._camera = { ...this._camera || {}, halation: enabled };
1450
+ return this;
1451
+ }
1452
+ // --- Lighting Methods ---
1453
+ lighting(settings) {
1454
+ this._lighting = { ...this._lighting || {}, ...settings };
1455
+ return this;
1456
+ }
1457
+ lightingType(type) {
1458
+ this._lighting = { ...this._lighting || {}, type };
1459
+ return this;
1460
+ }
1461
+ timeOfDay(time) {
1462
+ this._lighting = { ...this._lighting || {}, time };
1463
+ this._scene = { ...this._scene || { description: "" }, timeOfDay: time };
1464
+ return this;
1465
+ }
1466
+ weather(weather) {
1467
+ this._lighting = { ...this._lighting || {}, weather };
1468
+ this._scene = { ...this._scene || { description: "" }, weather };
1469
+ return this;
1470
+ }
1471
+ // --- Action & Motion Methods ---
1472
+ action(action, options = {}) {
1473
+ this._actions.push({
1474
+ beat: this._actions.length + 1,
1475
+ action,
1476
+ ...options
1477
+ });
1478
+ return this;
1479
+ }
1480
+ actions(actions) {
1481
+ actions.forEach((a, i) => this._actions.push({ beat: i + 1, action: a }));
1482
+ return this;
1483
+ }
1484
+ motion(settings) {
1485
+ this._motion = { ...this._motion || {}, ...settings };
1486
+ return this;
1487
+ }
1488
+ motionBeats(beats) {
1489
+ this._motion = { ...this._motion || {}, beats };
1490
+ return this;
1491
+ }
1492
+ // --- Style Methods ---
1493
+ style(settings) {
1494
+ this._style = { ...this._style || {}, ...settings };
1495
+ return this;
1496
+ }
1497
+ format(format) {
1498
+ this._style = { ...this._style || {}, format };
1499
+ return this;
1500
+ }
1501
+ era(era) {
1502
+ this._style = { ...this._style || {}, era };
1503
+ return this;
1504
+ }
1505
+ styleFilmStock(stock) {
1506
+ this._style = { ...this._style || {}, filmStock: stock };
1507
+ return this;
1508
+ }
1509
+ look(look) {
1510
+ this._style = { ...this._style || {}, look };
1511
+ return this;
1512
+ }
1513
+ reference(references) {
1514
+ this._style = { ...this._style || {}, reference: references };
1515
+ return this;
1516
+ }
1517
+ // --- Color Methods ---
1518
+ color(settings) {
1519
+ this._color = { ...this._color || {}, ...settings };
1520
+ return this;
1521
+ }
1522
+ palette(palette) {
1523
+ this._color = { ...this._color || {}, palette };
1524
+ return this;
1525
+ }
1526
+ colorAnchors(anchors) {
1527
+ this._color = { ...this._color || {}, anchors };
1528
+ return this;
1529
+ }
1530
+ colorGrade(grade) {
1531
+ this._color = { ...this._color || {}, grade };
1532
+ return this;
1533
+ }
1534
+ // --- Audio Methods ---
1535
+ audio(settings) {
1536
+ this._audio = { ...this._audio || {}, ...settings };
1537
+ return this;
1538
+ }
1539
+ dialogue(dialogue) {
1540
+ this._audio = { ...this._audio || {}, dialogue };
1541
+ return this;
1542
+ }
1543
+ ambient(ambient) {
1544
+ this._audio = { ...this._audio || {}, ambient };
1545
+ return this;
1546
+ }
1547
+ diegetic(sounds) {
1548
+ this._audio = { ...this._audio || {}, diegetic: sounds };
1549
+ return this;
1550
+ }
1551
+ soundEffects(effects) {
1552
+ this._audio = { ...this._audio || {}, soundEffects: effects };
1553
+ return this;
1554
+ }
1555
+ music(music) {
1556
+ this._audio = { ...this._audio || {}, music };
1557
+ return this;
1558
+ }
1559
+ // --- Technical Methods ---
1560
+ technical(settings) {
1561
+ this._technical = { ...this._technical || {}, ...settings };
1562
+ return this;
1563
+ }
1564
+ duration(seconds) {
1565
+ this._technical = { ...this._technical || {}, duration: seconds };
1566
+ return this;
1567
+ }
1568
+ resolution(res) {
1569
+ this._technical = { ...this._technical || {}, resolution: res };
1570
+ return this;
1571
+ }
1572
+ fps(fps) {
1573
+ this._technical = { ...this._technical || {}, fps };
1574
+ return this;
1575
+ }
1576
+ aspectRatio(ratio) {
1577
+ this._technical = { ...this._technical || {}, aspectRatio: ratio };
1578
+ return this;
1579
+ }
1580
+ // --- Shot List Methods ---
1581
+ addShot(shot) {
1582
+ this._shots.push(shot);
1583
+ return this;
1584
+ }
1585
+ shotList(shots) {
1586
+ this._shots = [...this._shots, ...shots];
1587
+ return this;
1588
+ }
1589
+ // --- Mood & Pacing ---
1590
+ mood(mood) {
1591
+ this._mood = mood;
1592
+ return this;
1593
+ }
1594
+ pacing(pacing) {
1595
+ this._pacing = pacing;
1596
+ return this;
1597
+ }
1598
+ transition(transition) {
1599
+ this._transitions.push(transition);
1600
+ return this;
1601
+ }
1602
+ transitions(transitions) {
1603
+ this._transitions = [...this._transitions, ...transitions];
1604
+ return this;
1605
+ }
1606
+ custom(text) {
1607
+ this._custom.push(text);
1608
+ return this;
1609
+ }
1610
+ // --- Build Methods ---
1611
+ buildPromptText() {
1612
+ const sections = [];
1613
+ if (this._scene) {
1614
+ let sceneText = this._scene.description;
1615
+ if (this._scene.setting) sceneText = `${this._scene.setting}. ${sceneText}`;
1616
+ if (this._scene.atmosphere) sceneText += `, ${this._scene.atmosphere} atmosphere`;
1617
+ sections.push(sceneText);
1618
+ }
1619
+ if (this._subject) {
1620
+ let subjectText = this._subject.main;
1621
+ if (this._subject.appearance) subjectText += `, ${this._subject.appearance}`;
1622
+ if (this._subject.clothing) subjectText += `, wearing ${this._subject.clothing}`;
1623
+ sections.push(subjectText);
1624
+ }
1625
+ const cinematography = [];
1626
+ if (this._camera) {
1627
+ if (this._camera.shot) cinematography.push(`${this._camera.shot} shot`);
1628
+ if (this._camera.angle) cinematography.push(this._camera.angle);
1629
+ if (this._camera.movement) cinematography.push(`${this._camera.movement} camera`);
1630
+ if (this._camera.lens) cinematography.push(`${this._camera.lens} lens`);
1631
+ if (this._camera.platform) cinematography.push(this._camera.platform);
1632
+ if (this._camera.focus) cinematography.push(`${this._camera.focus} focus`);
1633
+ }
1634
+ if (cinematography.length) {
1635
+ sections.push(`Cinematography: ${cinematography.join(", ")}`);
1636
+ }
1637
+ if (this._lighting) {
1638
+ const lightParts = [];
1639
+ if (this._lighting.type) {
1640
+ const types = Array.isArray(this._lighting.type) ? this._lighting.type : [this._lighting.type];
1641
+ lightParts.push(`${types.join(" and ")} lighting`);
1642
+ }
1643
+ if (this._lighting.time) lightParts.push(this._lighting.time);
1644
+ if (this._lighting.weather) lightParts.push(`${this._lighting.weather} weather`);
1645
+ if (this._lighting.intensity) lightParts.push(`${this._lighting.intensity} light`);
1646
+ if (this._lighting.sources?.length) lightParts.push(`light sources: ${this._lighting.sources.join(", ")}`);
1647
+ if (lightParts.length) sections.push(`Lighting: ${lightParts.join(", ")}`);
1648
+ }
1649
+ if (this._actions.length) {
1650
+ const actionText = this._actions.map((a) => `- ${a.action}`).join("\n");
1651
+ sections.push(`Actions:
1652
+ ${actionText}`);
1653
+ }
1654
+ if (this._motion?.beats?.length) {
1655
+ sections.push(`Motion beats: ${this._motion.beats.join(", ")}`);
1656
+ }
1657
+ if (this._style) {
1658
+ const styleParts = [];
1659
+ if (this._style.format) styleParts.push(this._style.format);
1660
+ if (this._style.era) styleParts.push(this._style.era);
1661
+ if (this._style.filmStock) styleParts.push(`shot on ${this._style.filmStock}`);
1662
+ if (this._style.look) {
1663
+ const looks = Array.isArray(this._style.look) ? this._style.look : [this._style.look];
1664
+ styleParts.push(looks.join(", "));
1665
+ }
1666
+ if (styleParts.length) sections.push(`Style: ${styleParts.join(", ")}`);
1667
+ }
1668
+ if (this._color) {
1669
+ const colorParts = [];
1670
+ if (this._color.palette) {
1671
+ const palettes = Array.isArray(this._color.palette) ? this._color.palette : [this._color.palette];
1672
+ colorParts.push(`${palettes.join(" and ")} palette`);
1673
+ }
1674
+ if (this._color.anchors?.length) colorParts.push(`color anchors: ${this._color.anchors.join(", ")}`);
1675
+ if (this._color.grade) colorParts.push(this._color.grade);
1676
+ if (colorParts.length) sections.push(`Color: ${colorParts.join(", ")}`);
1677
+ }
1678
+ if (this._audio) {
1679
+ const audioParts = [];
1680
+ if (this._audio.dialogue) audioParts.push(`Dialogue: "${this._audio.dialogue}"`);
1681
+ if (this._audio.ambient) audioParts.push(`Ambient: ${this._audio.ambient}`);
1682
+ if (this._audio.diegetic?.length) audioParts.push(`Diegetic sounds: ${this._audio.diegetic.join(", ")}`);
1683
+ if (this._audio.music) audioParts.push(`Music: ${this._audio.music}`);
1684
+ if (audioParts.length) sections.push(`Audio:
1685
+ ${audioParts.join("\n")}`);
1686
+ }
1687
+ if (this._mood) {
1688
+ const moods = Array.isArray(this._mood) ? this._mood : [this._mood];
1689
+ sections.push(`Mood: ${moods.join(", ")}`);
1690
+ }
1691
+ if (this._pacing) {
1692
+ sections.push(`Pacing: ${this._pacing}`);
1693
+ }
1694
+ if (this._custom.length) {
1695
+ sections.push(this._custom.join("\n"));
1696
+ }
1697
+ return sections.join("\n\n");
1698
+ }
1699
+ build() {
1700
+ return {
1701
+ prompt: this.buildPromptText(),
1702
+ structure: {
1703
+ scene: this._scene,
1704
+ subject: this._subject,
1705
+ camera: this._camera,
1706
+ lighting: this._lighting,
1707
+ actions: this._actions.length ? this._actions : void 0,
1708
+ motion: this._motion,
1709
+ style: this._style,
1710
+ color: this._color,
1711
+ audio: this._audio,
1712
+ technical: this._technical,
1713
+ shots: this._shots.length ? this._shots : void 0,
1714
+ mood: this._mood,
1715
+ pacing: this._pacing,
1716
+ transitions: this._transitions.length ? this._transitions : void 0
1717
+ }
1718
+ };
1719
+ }
1720
+ toString() {
1721
+ return this.build().prompt;
1722
+ }
1723
+ toJSON() {
1724
+ return JSON.stringify(this.build().structure, null, 2);
1725
+ }
1726
+ toYAML() {
1727
+ return objectToYaml2(this.build().structure);
1728
+ }
1729
+ toMarkdown() {
1730
+ const built = this.build();
1731
+ const sections = ["# Video Prompt\n"];
1732
+ sections.push("## Prompt\n```\n" + built.prompt + "\n```\n");
1733
+ if (built.structure.scene) {
1734
+ sections.push("## Scene\n" + objectToMarkdownList2(built.structure.scene));
1735
+ }
1736
+ if (built.structure.subject) {
1737
+ sections.push("## Subject\n" + objectToMarkdownList2(built.structure.subject));
1738
+ }
1739
+ if (built.structure.camera) {
1740
+ sections.push("## Camera\n" + objectToMarkdownList2(built.structure.camera));
1741
+ }
1742
+ if (built.structure.lighting) {
1743
+ sections.push("## Lighting\n" + objectToMarkdownList2(built.structure.lighting));
1744
+ }
1745
+ if (built.structure.actions) {
1746
+ sections.push("## Actions\n" + built.structure.actions.map((a) => `- **Beat ${a.beat}:** ${a.action}`).join("\n"));
1747
+ }
1748
+ if (built.structure.style) {
1749
+ sections.push("## Style\n" + objectToMarkdownList2(built.structure.style));
1750
+ }
1751
+ if (built.structure.audio) {
1752
+ sections.push("## Audio\n" + objectToMarkdownList2(built.structure.audio));
1753
+ }
1754
+ if (built.structure.technical) {
1755
+ sections.push("## Technical\n" + objectToMarkdownList2(built.structure.technical));
1756
+ }
1757
+ return sections.join("\n");
1758
+ }
1759
+ outputFormat(fmt) {
1760
+ switch (fmt) {
1761
+ case "json":
1762
+ return this.toJSON();
1763
+ case "yaml":
1764
+ return this.toYAML();
1765
+ case "markdown":
1766
+ return this.toMarkdown();
1767
+ default:
1768
+ return this.toString();
1769
+ }
1770
+ }
1771
+ };
1772
+ function objectToYaml2(obj, indent = 0) {
1773
+ const spaces = " ".repeat(indent);
1774
+ const lines = [];
1775
+ for (const [key, value] of Object.entries(obj)) {
1776
+ if (value === void 0 || value === null) continue;
1777
+ if (Array.isArray(value)) {
1778
+ if (value.length === 0) continue;
1779
+ lines.push(`${spaces}${key}:`);
1780
+ for (const item of value) {
1781
+ if (typeof item === "object") {
1782
+ lines.push(`${spaces} -`);
1783
+ lines.push(objectToYaml2(item, indent + 2).replace(/^/gm, " "));
1784
+ } else {
1785
+ lines.push(`${spaces} - ${item}`);
1786
+ }
1787
+ }
1788
+ } else if (typeof value === "object") {
1789
+ lines.push(`${spaces}${key}:`);
1790
+ lines.push(objectToYaml2(value, indent + 1));
1791
+ } else {
1792
+ lines.push(`${spaces}${key}: ${value}`);
1793
+ }
1794
+ }
1795
+ return lines.join("\n");
1796
+ }
1797
+ function objectToMarkdownList2(obj, indent = 0) {
1798
+ const spaces = " ".repeat(indent);
1799
+ const lines = [];
1800
+ for (const [key, value] of Object.entries(obj)) {
1801
+ if (value === void 0 || value === null) continue;
1802
+ if (Array.isArray(value)) {
1803
+ lines.push(`${spaces}- **${key}:** ${value.join(", ")}`);
1804
+ } else if (typeof value === "object") {
1805
+ lines.push(`${spaces}- **${key}:**`);
1806
+ lines.push(objectToMarkdownList2(value, indent + 1));
1807
+ } else {
1808
+ lines.push(`${spaces}- **${key}:** ${value}`);
1809
+ }
1810
+ }
1811
+ return lines.join("\n");
1812
+ }
1813
+ function video() {
1814
+ return new VideoPromptBuilder();
1815
+ }
1816
+
1817
+ // src/builder/audio.ts
1818
+ var AudioPromptBuilder = class {
1819
+ constructor() {
1820
+ this._tags = [];
1821
+ this._custom = [];
1822
+ }
1823
+ // --- Genre Methods ---
1824
+ genre(primary) {
1825
+ if (typeof primary === "string") {
1826
+ this._genre = { ...this._genre || { primary: "pop" }, primary };
1827
+ } else {
1828
+ this._genre = { ...this._genre || { primary: "pop" }, ...primary };
1829
+ }
1830
+ return this;
1831
+ }
1832
+ subgenre(subgenre) {
1833
+ this._genre = { ...this._genre || { primary: "pop" }, subgenre };
1834
+ return this;
1835
+ }
1836
+ fusion(genres) {
1837
+ this._genre = {
1838
+ ...this._genre || { primary: "pop" },
1839
+ secondary: genres,
1840
+ fusion: genres
1841
+ };
1842
+ return this;
1843
+ }
1844
+ // --- Mood Methods ---
1845
+ mood(primary, ...secondary) {
1846
+ this._mood = {
1847
+ primary,
1848
+ secondary: secondary.length ? secondary : void 0
1849
+ };
1850
+ return this;
1851
+ }
1852
+ energy(level) {
1853
+ this._mood = { ...this._mood || { primary: "energetic" }, energy: level };
1854
+ return this;
1855
+ }
1856
+ emotion(emotion) {
1857
+ this._mood = { ...this._mood || { primary: "emotional" }, emotion };
1858
+ return this;
1859
+ }
1860
+ // --- Tempo Methods ---
1861
+ tempo(bpmOrSettings) {
1862
+ if (typeof bpmOrSettings === "number") {
1863
+ this._tempo = { ...this._tempo || {}, bpm: bpmOrSettings };
1864
+ } else {
1865
+ this._tempo = { ...this._tempo || {}, ...bpmOrSettings };
1866
+ }
1867
+ return this;
1868
+ }
1869
+ bpm(bpm) {
1870
+ this._tempo = { ...this._tempo || {}, bpm };
1871
+ return this;
1872
+ }
1873
+ tempoMarking(marking) {
1874
+ this._tempo = { ...this._tempo || {}, marking };
1875
+ return this;
1876
+ }
1877
+ tempoFeel(feel) {
1878
+ this._tempo = { ...this._tempo || {}, feel };
1879
+ return this;
1880
+ }
1881
+ // --- Vocal Methods ---
1882
+ vocals(settings) {
1883
+ this._vocals = { ...this._vocals || {}, ...settings };
1884
+ return this;
1885
+ }
1886
+ vocalStyle(style) {
1887
+ this._vocals = { ...this._vocals || {}, style };
1888
+ return this;
1889
+ }
1890
+ language(language) {
1891
+ this._vocals = { ...this._vocals || {}, language };
1892
+ return this;
1893
+ }
1894
+ lyrics(lyrics) {
1895
+ this._vocals = { ...this._vocals || {}, lyrics };
1896
+ return this;
1897
+ }
1898
+ lyricsTheme(theme) {
1899
+ this._vocals = { ...this._vocals || {}, theme };
1900
+ return this;
1901
+ }
1902
+ delivery(delivery) {
1903
+ this._vocals = { ...this._vocals || {}, delivery };
1904
+ return this;
1905
+ }
1906
+ instrumental() {
1907
+ this._vocals = { ...this._vocals || {}, language: "instrumental" };
1908
+ return this;
1909
+ }
1910
+ // --- Instrumentation Methods ---
1911
+ instruments(instruments) {
1912
+ this._instrumentation = {
1913
+ ...this._instrumentation || {},
1914
+ lead: instruments
1915
+ };
1916
+ return this;
1917
+ }
1918
+ instrumentation(settings) {
1919
+ this._instrumentation = { ...this._instrumentation || {}, ...settings };
1920
+ return this;
1921
+ }
1922
+ leadInstrument(instrument) {
1923
+ this._instrumentation = { ...this._instrumentation || {}, lead: instrument };
1924
+ return this;
1925
+ }
1926
+ rhythmSection(instruments) {
1927
+ this._instrumentation = { ...this._instrumentation || {}, rhythm: instruments };
1928
+ return this;
1929
+ }
1930
+ bassInstrument(instrument) {
1931
+ this._instrumentation = { ...this._instrumentation || {}, bass: instrument };
1932
+ return this;
1933
+ }
1934
+ percussion(instruments) {
1935
+ this._instrumentation = { ...this._instrumentation || {}, percussion: instruments };
1936
+ return this;
1937
+ }
1938
+ pads(instruments) {
1939
+ this._instrumentation = { ...this._instrumentation || {}, pads: instruments };
1940
+ return this;
1941
+ }
1942
+ featuredInstrument(instrument) {
1943
+ this._instrumentation = { ...this._instrumentation || {}, featured: instrument };
1944
+ return this;
1945
+ }
1946
+ // --- Structure Methods ---
1947
+ structure(settings) {
1948
+ if ("sections" in settings || "form" in settings || "duration" in settings) {
1949
+ this._structure = { ...this._structure || {}, ...settings };
1950
+ } else {
1951
+ const sections = [];
1952
+ for (const [type, bars] of Object.entries(settings)) {
1953
+ if (typeof bars === "number") {
1954
+ sections.push({ type, bars });
1955
+ }
1956
+ }
1957
+ this._structure = { ...this._structure || {}, sections };
1958
+ }
1959
+ return this;
1960
+ }
1961
+ section(type, bars, description) {
1962
+ const sections = this._structure?.sections || [];
1963
+ sections.push({ type, bars, description });
1964
+ this._structure = { ...this._structure || {}, sections };
1965
+ return this;
1966
+ }
1967
+ form(form) {
1968
+ this._structure = { ...this._structure || {}, form };
1969
+ return this;
1970
+ }
1971
+ duration(seconds) {
1972
+ this._structure = { ...this._structure || {}, duration: seconds };
1973
+ return this;
1974
+ }
1975
+ // --- Production Methods ---
1976
+ production(settings) {
1977
+ this._production = { ...this._production || {}, ...settings };
1978
+ return this;
1979
+ }
1980
+ productionStyle(style) {
1981
+ this._production = { ...this._production || {}, style };
1982
+ return this;
1983
+ }
1984
+ era(era) {
1985
+ this._production = { ...this._production || {}, era };
1986
+ return this;
1987
+ }
1988
+ reference(artists) {
1989
+ this._production = { ...this._production || {}, reference: artists };
1990
+ return this;
1991
+ }
1992
+ texture(texture) {
1993
+ this._production = { ...this._production || {}, texture };
1994
+ return this;
1995
+ }
1996
+ effects(effects) {
1997
+ this._production = { ...this._production || {}, effects };
1998
+ return this;
1999
+ }
2000
+ // --- Technical Methods ---
2001
+ technical(settings) {
2002
+ this._technical = { ...this._technical || {}, ...settings };
2003
+ return this;
2004
+ }
2005
+ key(key) {
2006
+ this._technical = { ...this._technical || {}, key };
2007
+ return this;
2008
+ }
2009
+ timeSignature(sig) {
2010
+ this._technical = { ...this._technical || {}, timeSignature: sig };
2011
+ return this;
2012
+ }
2013
+ formatType(format) {
2014
+ this._technical = { ...this._technical || {}, format };
2015
+ return this;
2016
+ }
2017
+ // --- Tags & Custom ---
2018
+ tag(tag) {
2019
+ this._tags.push(tag);
2020
+ return this;
2021
+ }
2022
+ tags(tags) {
2023
+ this._tags = [...this._tags, ...tags];
2024
+ return this;
2025
+ }
2026
+ custom(text) {
2027
+ this._custom.push(text);
2028
+ return this;
2029
+ }
2030
+ // --- Build Methods ---
2031
+ buildStylePrompt() {
2032
+ const parts = [];
2033
+ if (this._genre) {
2034
+ let genreText = this._genre.primary;
2035
+ if (this._genre.subgenre) genreText = `${this._genre.subgenre} ${genreText}`;
2036
+ if (this._genre.secondary?.length) {
2037
+ genreText += ` with ${this._genre.secondary.join(" and ")} influences`;
2038
+ }
2039
+ parts.push(genreText);
2040
+ }
2041
+ if (this._mood) {
2042
+ let moodText = String(this._mood.primary);
2043
+ if (this._mood.secondary?.length) {
2044
+ moodText += `, ${this._mood.secondary.join(", ")}`;
2045
+ }
2046
+ if (this._mood.energy) moodText += `, ${this._mood.energy} energy`;
2047
+ parts.push(moodText);
2048
+ }
2049
+ if (this._tempo) {
2050
+ const tempoParts = [];
2051
+ if (this._tempo.bpm) tempoParts.push(`${this._tempo.bpm} BPM`);
2052
+ if (this._tempo.marking) tempoParts.push(this._tempo.marking);
2053
+ if (this._tempo.feel) tempoParts.push(`${this._tempo.feel} feel`);
2054
+ if (tempoParts.length) parts.push(tempoParts.join(", "));
2055
+ }
2056
+ if (this._instrumentation) {
2057
+ const instrParts = [];
2058
+ if (this._instrumentation.lead) {
2059
+ const leads = Array.isArray(this._instrumentation.lead) ? this._instrumentation.lead : [this._instrumentation.lead];
2060
+ instrParts.push(leads.join(", "));
2061
+ }
2062
+ if (this._instrumentation.featured) {
2063
+ instrParts.push(`featuring ${this._instrumentation.featured}`);
2064
+ }
2065
+ if (instrParts.length) parts.push(instrParts.join(", "));
2066
+ }
2067
+ if (this._vocals) {
2068
+ const vocalParts = [];
2069
+ if (this._vocals.language === "instrumental") {
2070
+ vocalParts.push("instrumental");
2071
+ } else {
2072
+ if (this._vocals.style) {
2073
+ const styles = Array.isArray(this._vocals.style) ? this._vocals.style : [this._vocals.style];
2074
+ vocalParts.push(`${styles.join(" and ")} vocals`);
2075
+ }
2076
+ if (this._vocals.language && this._vocals.language !== "english") {
2077
+ vocalParts.push(`in ${this._vocals.language}`);
2078
+ }
2079
+ }
2080
+ if (vocalParts.length) parts.push(vocalParts.join(" "));
2081
+ }
2082
+ if (this._production) {
2083
+ const prodParts = [];
2084
+ if (this._production.style) {
2085
+ const styles = Array.isArray(this._production.style) ? this._production.style : [this._production.style];
2086
+ prodParts.push(`${styles.join(", ")} production`);
2087
+ }
2088
+ if (this._production.era) prodParts.push(`${this._production.era} sound`);
2089
+ if (this._production.texture) prodParts.push(this._production.texture);
2090
+ if (prodParts.length) parts.push(prodParts.join(", "));
2091
+ }
2092
+ if (this._technical) {
2093
+ const techParts = [];
2094
+ if (this._technical.key) techParts.push(`in the key of ${this._technical.key}`);
2095
+ if (this._technical.timeSignature && this._technical.timeSignature !== "4/4") {
2096
+ techParts.push(`${this._technical.timeSignature} time`);
2097
+ }
2098
+ if (techParts.length) parts.push(techParts.join(", "));
2099
+ }
2100
+ if (this._tags.length) {
2101
+ parts.push(this._tags.join(", "));
2102
+ }
2103
+ if (this._custom.length) {
2104
+ parts.push(this._custom.join(", "));
2105
+ }
2106
+ return parts.join(", ");
2107
+ }
2108
+ buildLyricsPrompt() {
2109
+ if (!this._vocals?.lyrics && !this._vocals?.theme) return void 0;
2110
+ const parts = [];
2111
+ if (this._vocals.theme) {
2112
+ parts.push(`Theme: ${this._vocals.theme}`);
2113
+ }
2114
+ if (this._vocals.lyrics) {
2115
+ parts.push(this._vocals.lyrics);
2116
+ }
2117
+ return parts.join("\n\n");
2118
+ }
2119
+ buildFullPrompt() {
2120
+ const sections = [];
2121
+ sections.push(`Style: ${this.buildStylePrompt()}`);
2122
+ if (this._structure?.sections?.length) {
2123
+ const structureText = this._structure.sections.map((s) => `[${s.type.toUpperCase()}]${s.description ? ` ${s.description}` : ""}`).join("\n");
2124
+ sections.push(`Structure:
2125
+ ${structureText}`);
2126
+ }
2127
+ const lyrics = this.buildLyricsPrompt();
2128
+ if (lyrics) {
2129
+ sections.push(`Lyrics:
2130
+ ${lyrics}`);
2131
+ }
2132
+ return sections.join("\n\n");
2133
+ }
2134
+ build() {
2135
+ return {
2136
+ prompt: this.buildFullPrompt(),
2137
+ stylePrompt: this.buildStylePrompt(),
2138
+ lyricsPrompt: this.buildLyricsPrompt(),
2139
+ structure: {
2140
+ genre: this._genre,
2141
+ mood: this._mood,
2142
+ tempo: this._tempo,
2143
+ vocals: this._vocals,
2144
+ instrumentation: this._instrumentation,
2145
+ structure: this._structure,
2146
+ production: this._production,
2147
+ technical: this._technical,
2148
+ tags: this._tags.length ? this._tags : void 0
2149
+ }
2150
+ };
2151
+ }
2152
+ toString() {
2153
+ return this.build().prompt;
2154
+ }
2155
+ toStyleString() {
2156
+ return this.build().stylePrompt;
2157
+ }
2158
+ toJSON() {
2159
+ return JSON.stringify(this.build().structure, null, 2);
2160
+ }
2161
+ toYAML() {
2162
+ return objectToYaml3(this.build().structure);
2163
+ }
2164
+ toMarkdown() {
2165
+ const built = this.build();
2166
+ const sections = ["# Audio Prompt\n"];
2167
+ sections.push("## Style Prompt\n```\n" + built.stylePrompt + "\n```\n");
2168
+ if (built.lyricsPrompt) {
2169
+ sections.push("## Lyrics\n```\n" + built.lyricsPrompt + "\n```\n");
2170
+ }
2171
+ if (built.structure.genre) {
2172
+ sections.push("## Genre\n" + objectToMarkdownList3(built.structure.genre));
2173
+ }
2174
+ if (built.structure.mood) {
2175
+ sections.push("## Mood\n" + objectToMarkdownList3(built.structure.mood));
2176
+ }
2177
+ if (built.structure.tempo) {
2178
+ sections.push("## Tempo\n" + objectToMarkdownList3(built.structure.tempo));
2179
+ }
2180
+ if (built.structure.vocals) {
2181
+ sections.push("## Vocals\n" + objectToMarkdownList3(built.structure.vocals));
2182
+ }
2183
+ if (built.structure.instrumentation) {
2184
+ sections.push("## Instrumentation\n" + objectToMarkdownList3(built.structure.instrumentation));
2185
+ }
2186
+ if (built.structure.production) {
2187
+ sections.push("## Production\n" + objectToMarkdownList3(built.structure.production));
2188
+ }
2189
+ return sections.join("\n");
2190
+ }
2191
+ outputFormat(fmt) {
2192
+ switch (fmt) {
2193
+ case "json":
2194
+ return this.toJSON();
2195
+ case "yaml":
2196
+ return this.toYAML();
2197
+ case "markdown":
2198
+ return this.toMarkdown();
2199
+ default:
2200
+ return this.toString();
2201
+ }
2202
+ }
2203
+ };
2204
+ function objectToYaml3(obj, indent = 0) {
2205
+ const spaces = " ".repeat(indent);
2206
+ const lines = [];
2207
+ for (const [key, value] of Object.entries(obj)) {
2208
+ if (value === void 0 || value === null) continue;
2209
+ if (Array.isArray(value)) {
2210
+ if (value.length === 0) continue;
2211
+ lines.push(`${spaces}${key}:`);
2212
+ for (const item of value) {
2213
+ if (typeof item === "object") {
2214
+ lines.push(`${spaces} -`);
2215
+ lines.push(objectToYaml3(item, indent + 2).replace(/^/gm, " "));
2216
+ } else {
2217
+ lines.push(`${spaces} - ${item}`);
2218
+ }
2219
+ }
2220
+ } else if (typeof value === "object") {
2221
+ lines.push(`${spaces}${key}:`);
2222
+ lines.push(objectToYaml3(value, indent + 1));
2223
+ } else {
2224
+ lines.push(`${spaces}${key}: ${value}`);
2225
+ }
2226
+ }
2227
+ return lines.join("\n");
2228
+ }
2229
+ function objectToMarkdownList3(obj, indent = 0) {
2230
+ const spaces = " ".repeat(indent);
2231
+ const lines = [];
2232
+ for (const [key, value] of Object.entries(obj)) {
2233
+ if (value === void 0 || value === null) continue;
2234
+ if (Array.isArray(value)) {
2235
+ lines.push(`${spaces}- **${key}:** ${value.join(", ")}`);
2236
+ } else if (typeof value === "object") {
2237
+ lines.push(`${spaces}- **${key}:**`);
2238
+ lines.push(objectToMarkdownList3(value, indent + 1));
2239
+ } else {
2240
+ lines.push(`${spaces}- **${key}:** ${value}`);
2241
+ }
2242
+ }
2243
+ return lines.join("\n");
2244
+ }
2245
+ function audio() {
2246
+ return new AudioPromptBuilder();
2247
+ }
2248
+
2249
+ // src/builder/chat.ts
2250
+ var ChatPromptBuilder = class {
2251
+ constructor() {
2252
+ this._messages = [];
2253
+ this._examples = [];
2254
+ this._customSystemParts = [];
2255
+ }
2256
+ // --- Message Methods ---
2257
+ system(content) {
2258
+ this._messages = this._messages.filter((m) => m.role !== "system");
2259
+ this._messages.unshift({ role: "system", content });
2260
+ return this;
2261
+ }
2262
+ user(content, name) {
2263
+ this._messages.push({ role: "user", content, name });
2264
+ return this;
2265
+ }
2266
+ assistant(content) {
2267
+ this._messages.push({ role: "assistant", content });
2268
+ return this;
2269
+ }
2270
+ message(role, content, name) {
2271
+ this._messages.push({ role, content, name });
2272
+ return this;
2273
+ }
2274
+ messages(messages) {
2275
+ this._messages = [...this._messages, ...messages];
2276
+ return this;
2277
+ }
2278
+ conversation(turns) {
2279
+ for (const turn of turns) {
2280
+ this.user(turn.user);
2281
+ if (turn.assistant) {
2282
+ this.assistant(turn.assistant);
2283
+ }
2284
+ }
2285
+ return this;
2286
+ }
2287
+ // --- Persona Methods ---
2288
+ persona(settings) {
2289
+ if (typeof settings === "string") {
2290
+ this._persona = { ...this._persona || {}, role: settings };
2291
+ } else {
2292
+ this._persona = { ...this._persona || {}, ...settings };
2293
+ }
2294
+ return this;
2295
+ }
2296
+ role(role) {
2297
+ this._persona = { ...this._persona || {}, role };
2298
+ return this;
2299
+ }
2300
+ tone(tone) {
2301
+ this._persona = { ...this._persona || {}, tone };
2302
+ return this;
2303
+ }
2304
+ expertise(expertise) {
2305
+ this._persona = { ...this._persona || {}, expertise };
2306
+ return this;
2307
+ }
2308
+ personality(traits) {
2309
+ this._persona = { ...this._persona || {}, personality: traits };
2310
+ return this;
2311
+ }
2312
+ background(background) {
2313
+ this._persona = { ...this._persona || {}, background };
2314
+ return this;
2315
+ }
2316
+ speakAs(name) {
2317
+ this._persona = { ...this._persona || {}, name };
2318
+ return this;
2319
+ }
2320
+ responseLanguage(language) {
2321
+ this._persona = { ...this._persona || {}, language };
2322
+ return this;
2323
+ }
2324
+ // --- Context Methods ---
2325
+ context(settings) {
2326
+ if (typeof settings === "string") {
2327
+ this._context = { ...this._context || {}, background: settings };
2328
+ } else {
2329
+ this._context = { ...this._context || {}, ...settings };
2330
+ }
2331
+ return this;
2332
+ }
2333
+ domain(domain) {
2334
+ this._context = { ...this._context || {}, domain };
2335
+ return this;
2336
+ }
2337
+ audience(audience) {
2338
+ this._context = { ...this._context || {}, audience };
2339
+ return this;
2340
+ }
2341
+ purpose(purpose) {
2342
+ this._context = { ...this._context || {}, purpose };
2343
+ return this;
2344
+ }
2345
+ constraints(constraints) {
2346
+ const existing = this._context?.constraints || [];
2347
+ this._context = { ...this._context || {}, constraints: [...existing, ...constraints] };
2348
+ return this;
2349
+ }
2350
+ constraint(constraint) {
2351
+ return this.constraints([constraint]);
2352
+ }
2353
+ assumptions(assumptions) {
2354
+ this._context = { ...this._context || {}, assumptions };
2355
+ return this;
2356
+ }
2357
+ knowledge(facts) {
2358
+ this._context = { ...this._context || {}, knowledge: facts };
2359
+ return this;
2360
+ }
2361
+ // --- Task Methods ---
2362
+ task(instruction) {
2363
+ if (typeof instruction === "string") {
2364
+ this._task = { ...this._task || { instruction: "" }, instruction };
2365
+ } else {
2366
+ this._task = { ...this._task || { instruction: "" }, ...instruction };
2367
+ }
2368
+ return this;
2369
+ }
2370
+ instruction(instruction) {
2371
+ this._task = { ...this._task || { instruction: "" }, instruction };
2372
+ return this;
2373
+ }
2374
+ steps(steps) {
2375
+ this._task = { ...this._task || { instruction: "" }, steps };
2376
+ return this;
2377
+ }
2378
+ deliverables(deliverables) {
2379
+ this._task = { ...this._task || { instruction: "" }, deliverables };
2380
+ return this;
2381
+ }
2382
+ criteria(criteria) {
2383
+ this._task = { ...this._task || { instruction: "" }, criteria };
2384
+ return this;
2385
+ }
2386
+ avoid(antiPatterns) {
2387
+ this._task = { ...this._task || { instruction: "" }, antiPatterns };
2388
+ return this;
2389
+ }
2390
+ priority(priority) {
2391
+ this._task = { ...this._task || { instruction: "" }, priority };
2392
+ return this;
2393
+ }
2394
+ // --- Example Methods ---
2395
+ example(input, output, explanation) {
2396
+ this._examples.push({ input, output, explanation });
2397
+ return this;
2398
+ }
2399
+ examples(examples) {
2400
+ this._examples = [...this._examples, ...examples];
2401
+ return this;
2402
+ }
2403
+ fewShot(examples) {
2404
+ for (const ex of examples) {
2405
+ this._examples.push(ex);
2406
+ }
2407
+ return this;
2408
+ }
2409
+ // --- Output Methods ---
2410
+ output(settings) {
2411
+ this._output = { ...this._output || {}, ...settings };
2412
+ return this;
2413
+ }
2414
+ outputFormat(format) {
2415
+ this._output = {
2416
+ ...this._output || {},
2417
+ format: { type: format }
2418
+ };
2419
+ return this;
2420
+ }
2421
+ json(schema) {
2422
+ if (schema) {
2423
+ this._output = {
2424
+ ...this._output || {},
2425
+ format: { type: "json", jsonSchema: schema }
2426
+ };
2427
+ } else {
2428
+ this._output = {
2429
+ ...this._output || {},
2430
+ format: { type: "json" }
2431
+ };
2432
+ }
2433
+ return this;
2434
+ }
2435
+ jsonSchema(name, schema, description) {
2436
+ this._output = {
2437
+ ...this._output || {},
2438
+ format: {
2439
+ type: "json",
2440
+ jsonSchema: { name, schema, description }
2441
+ }
2442
+ };
2443
+ return this;
2444
+ }
2445
+ markdown() {
2446
+ this._output = { ...this._output || {}, format: { type: "markdown" } };
2447
+ return this;
2448
+ }
2449
+ code(language) {
2450
+ this._output = { ...this._output || {}, format: { type: "code", language } };
2451
+ return this;
2452
+ }
2453
+ table() {
2454
+ this._output = { ...this._output || {}, format: { type: "table" } };
2455
+ return this;
2456
+ }
2457
+ length(length) {
2458
+ this._output = { ...this._output || {}, length };
2459
+ return this;
2460
+ }
2461
+ style(style) {
2462
+ this._output = { ...this._output || {}, style };
2463
+ return this;
2464
+ }
2465
+ brief() {
2466
+ return this.length("brief");
2467
+ }
2468
+ moderate() {
2469
+ return this.length("moderate");
2470
+ }
2471
+ detailed() {
2472
+ return this.length("detailed");
2473
+ }
2474
+ comprehensive() {
2475
+ return this.length("comprehensive");
2476
+ }
2477
+ exhaustive() {
2478
+ return this.length("exhaustive");
2479
+ }
2480
+ withExamples() {
2481
+ this._output = { ...this._output || {}, includeExamples: true };
2482
+ return this;
2483
+ }
2484
+ withExplanation() {
2485
+ this._output = { ...this._output || {}, includeExplanation: true };
2486
+ return this;
2487
+ }
2488
+ withSources() {
2489
+ this._output = { ...this._output || {}, includeSources: true };
2490
+ return this;
2491
+ }
2492
+ withConfidence() {
2493
+ this._output = { ...this._output || {}, includeConfidence: true };
2494
+ return this;
2495
+ }
2496
+ // --- Reasoning Methods ---
2497
+ reasoning(settings) {
2498
+ this._reasoning = { ...this._reasoning || {}, ...settings };
2499
+ return this;
2500
+ }
2501
+ reasoningStyle(style) {
2502
+ this._reasoning = { ...this._reasoning || {}, style };
2503
+ return this;
2504
+ }
2505
+ stepByStep() {
2506
+ this._reasoning = { ...this._reasoning || {}, style: "step-by-step", showWork: true };
2507
+ return this;
2508
+ }
2509
+ chainOfThought() {
2510
+ this._reasoning = { ...this._reasoning || {}, style: "chain-of-thought", showWork: true };
2511
+ return this;
2512
+ }
2513
+ treeOfThought() {
2514
+ this._reasoning = { ...this._reasoning || {}, style: "tree-of-thought", showWork: true };
2515
+ return this;
2516
+ }
2517
+ firstPrinciples() {
2518
+ this._reasoning = { ...this._reasoning || {}, style: "first-principles", showWork: true };
2519
+ return this;
2520
+ }
2521
+ devilsAdvocate() {
2522
+ this._reasoning = { ...this._reasoning || {}, style: "devil-advocate", considerAlternatives: true };
2523
+ return this;
2524
+ }
2525
+ showWork(show = true) {
2526
+ this._reasoning = { ...this._reasoning || {}, showWork: show };
2527
+ return this;
2528
+ }
2529
+ verifyAnswer(verify = true) {
2530
+ this._reasoning = { ...this._reasoning || {}, verifyAnswer: verify };
2531
+ return this;
2532
+ }
2533
+ considerAlternatives(consider = true) {
2534
+ this._reasoning = { ...this._reasoning || {}, considerAlternatives: consider };
2535
+ return this;
2536
+ }
2537
+ explainAssumptions(explain = true) {
2538
+ this._reasoning = { ...this._reasoning || {}, explainAssumptions: explain };
2539
+ return this;
2540
+ }
2541
+ // --- Memory Methods ---
2542
+ memory(memory) {
2543
+ this._memory = { ...this._memory || {}, ...memory };
2544
+ return this;
2545
+ }
2546
+ remember(facts) {
2547
+ const existing = this._memory?.facts || [];
2548
+ this._memory = { ...this._memory || {}, facts: [...existing, ...facts] };
2549
+ return this;
2550
+ }
2551
+ preferences(prefs) {
2552
+ this._memory = { ...this._memory || {}, preferences: prefs };
2553
+ return this;
2554
+ }
2555
+ history(messages) {
2556
+ this._memory = { ...this._memory || {}, history: messages };
2557
+ return this;
2558
+ }
2559
+ summarizeHistory(summary) {
2560
+ this._memory = { ...this._memory || {}, summary };
2561
+ return this;
2562
+ }
2563
+ // --- Custom System Prompt Parts ---
2564
+ addSystemPart(part) {
2565
+ this._customSystemParts.push(part);
2566
+ return this;
2567
+ }
2568
+ raw(content) {
2569
+ this._customSystemParts = [content];
2570
+ return this;
2571
+ }
2572
+ // --- Build Methods ---
2573
+ buildSystemPrompt() {
2574
+ const parts = [];
2575
+ if (this._persona) {
2576
+ let personaText = "";
2577
+ if (this._persona.name) {
2578
+ personaText += `You are ${this._persona.name}`;
2579
+ if (this._persona.role) personaText += `, ${this._persona.role}`;
2580
+ personaText += ".";
2581
+ } else if (this._persona.role) {
2582
+ personaText += `You are ${this._persona.role}.`;
2583
+ }
2584
+ if (this._persona.tone) {
2585
+ const tones = Array.isArray(this._persona.tone) ? this._persona.tone : [this._persona.tone];
2586
+ personaText += ` Your tone is ${tones.join(" and ")}.`;
2587
+ }
2588
+ if (this._persona.expertise) {
2589
+ const areas = Array.isArray(this._persona.expertise) ? this._persona.expertise : [this._persona.expertise];
2590
+ personaText += ` You have expertise in ${areas.join(", ")}.`;
2591
+ }
2592
+ if (this._persona.personality?.length) {
2593
+ personaText += ` You are ${this._persona.personality.join(", ")}.`;
2594
+ }
2595
+ if (this._persona.background) {
2596
+ personaText += ` ${this._persona.background}`;
2597
+ }
2598
+ if (this._persona.verbosity) {
2599
+ personaText += ` Keep responses ${this._persona.verbosity}.`;
2600
+ }
2601
+ if (this._persona.language) {
2602
+ personaText += ` Respond in ${this._persona.language}.`;
2603
+ }
2604
+ if (personaText) parts.push(personaText.trim());
2605
+ }
2606
+ if (this._context) {
2607
+ const contextParts = [];
2608
+ if (this._context.background) {
2609
+ contextParts.push(this._context.background);
2610
+ }
2611
+ if (this._context.domain) {
2612
+ contextParts.push(`Domain: ${this._context.domain}`);
2613
+ }
2614
+ if (this._context.audience) {
2615
+ contextParts.push(`Target audience: ${this._context.audience}`);
2616
+ }
2617
+ if (this._context.purpose) {
2618
+ contextParts.push(`Purpose: ${this._context.purpose}`);
2619
+ }
2620
+ if (this._context.knowledge?.length) {
2621
+ contextParts.push(`Known facts:
2622
+ ${this._context.knowledge.map((k) => `- ${k}`).join("\n")}`);
2623
+ }
2624
+ if (this._context.assumptions?.length) {
2625
+ contextParts.push(`Assumptions:
2626
+ ${this._context.assumptions.map((a) => `- ${a}`).join("\n")}`);
2627
+ }
2628
+ if (contextParts.length) {
2629
+ parts.push(`## Context
2630
+ ${contextParts.join("\n")}`);
2631
+ }
2632
+ }
2633
+ if (this._task) {
2634
+ const taskParts = [];
2635
+ if (this._task.instruction) {
2636
+ taskParts.push(this._task.instruction);
2637
+ }
2638
+ if (this._task.priority) {
2639
+ taskParts.push(`Priority: ${this._task.priority}`);
2640
+ }
2641
+ if (this._task.steps?.length) {
2642
+ taskParts.push(`
2643
+ Steps:
2644
+ ${this._task.steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}`);
2645
+ }
2646
+ if (this._task.deliverables?.length) {
2647
+ taskParts.push(`
2648
+ Deliverables:
2649
+ ${this._task.deliverables.map((d) => `- ${d}`).join("\n")}`);
2650
+ }
2651
+ if (this._task.criteria?.length) {
2652
+ taskParts.push(`
2653
+ Success criteria:
2654
+ ${this._task.criteria.map((c) => `- ${c}`).join("\n")}`);
2655
+ }
2656
+ if (this._task.antiPatterns?.length) {
2657
+ taskParts.push(`
2658
+ Avoid:
2659
+ ${this._task.antiPatterns.map((a) => `- ${a}`).join("\n")}`);
2660
+ }
2661
+ if (taskParts.length) {
2662
+ parts.push(`## Task
2663
+ ${taskParts.join("\n")}`);
2664
+ }
2665
+ }
2666
+ if (this._context?.constraints?.length) {
2667
+ parts.push(`## Constraints
2668
+ ${this._context.constraints.map((c, i) => `${i + 1}. ${c}`).join("\n")}`);
2669
+ }
2670
+ if (this._examples.length) {
2671
+ const examplesText = this._examples.map((ex, i) => {
2672
+ let text = `### Example ${i + 1}
2673
+ **Input:** ${ex.input}
2674
+ **Output:** ${ex.output}`;
2675
+ if (ex.explanation) text += `
2676
+ **Explanation:** ${ex.explanation}`;
2677
+ return text;
2678
+ }).join("\n\n");
2679
+ parts.push(`## Examples
2680
+ ${examplesText}`);
2681
+ }
2682
+ if (this._output) {
2683
+ const outputParts = [];
2684
+ if (this._output.format) {
2685
+ switch (this._output.format.type) {
2686
+ case "json":
2687
+ if (this._output.format.jsonSchema) {
2688
+ outputParts.push(`Respond in valid JSON matching this schema:
2689
+ \`\`\`json
2690
+ ${JSON.stringify(this._output.format.jsonSchema.schema, null, 2)}
2691
+ \`\`\``);
2692
+ } else {
2693
+ outputParts.push("Respond in valid JSON format.");
2694
+ }
2695
+ break;
2696
+ case "markdown":
2697
+ outputParts.push("Format your response using Markdown.");
2698
+ break;
2699
+ case "code":
2700
+ outputParts.push(`Respond with code${this._output.format.language ? ` in ${this._output.format.language}` : ""}.`);
2701
+ break;
2702
+ case "table":
2703
+ outputParts.push("Format your response as a table.");
2704
+ break;
2705
+ }
2706
+ }
2707
+ if (this._output.length) {
2708
+ outputParts.push(`Keep your response ${this._output.length}.`);
2709
+ }
2710
+ if (this._output.style) {
2711
+ const styleMap = {
2712
+ "prose": "flowing prose",
2713
+ "bullet-points": "bullet points",
2714
+ "numbered-list": "a numbered list",
2715
+ "table": "a table",
2716
+ "code": "code",
2717
+ "mixed": "a mix of prose and lists",
2718
+ "qa": "Q&A format",
2719
+ "dialogue": "dialogue format"
2720
+ };
2721
+ outputParts.push(`Structure as ${styleMap[this._output.style]}.`);
2722
+ }
2723
+ if (this._output.language) {
2724
+ outputParts.push(`Respond in ${this._output.language}.`);
2725
+ }
2726
+ if (this._output.includeExamples) {
2727
+ outputParts.push("Include relevant examples.");
2728
+ }
2729
+ if (this._output.includeExplanation) {
2730
+ outputParts.push("Include clear explanations.");
2731
+ }
2732
+ if (this._output.includeSources) {
2733
+ outputParts.push("Cite your sources.");
2734
+ }
2735
+ if (this._output.includeConfidence) {
2736
+ outputParts.push("Include your confidence level in the answer.");
2737
+ }
2738
+ if (outputParts.length) {
2739
+ parts.push(`## Output Format
2740
+ ${outputParts.join("\n")}`);
2741
+ }
2742
+ }
2743
+ if (this._reasoning) {
2744
+ const reasoningParts = [];
2745
+ if (this._reasoning.style) {
2746
+ const styleInstructions = {
2747
+ "step-by-step": "Think through this step by step.",
2748
+ "chain-of-thought": "Use chain-of-thought reasoning to work through the problem.",
2749
+ "tree-of-thought": "Consider multiple approaches and evaluate each before deciding.",
2750
+ "direct": "Provide a direct answer.",
2751
+ "analytical": "Analyze the problem systematically.",
2752
+ "comparative": "Compare different options or approaches.",
2753
+ "deductive": "Use deductive reasoning from general principles.",
2754
+ "inductive": "Use inductive reasoning from specific examples.",
2755
+ "first-principles": "Reason from first principles, breaking down to fundamental truths.",
2756
+ "analogical": "Use analogies to explain and reason about the problem.",
2757
+ "devil-advocate": "Consider and argue against your own conclusions."
2758
+ };
2759
+ reasoningParts.push(styleInstructions[this._reasoning.style]);
2760
+ }
2761
+ if (this._reasoning.showWork) {
2762
+ reasoningParts.push("Show your reasoning process.");
2763
+ }
2764
+ if (this._reasoning.verifyAnswer) {
2765
+ reasoningParts.push("Verify your answer before presenting it.");
2766
+ }
2767
+ if (this._reasoning.considerAlternatives) {
2768
+ reasoningParts.push("Consider alternative perspectives and solutions.");
2769
+ }
2770
+ if (this._reasoning.explainAssumptions) {
2771
+ reasoningParts.push("Explicitly state any assumptions you make.");
2772
+ }
2773
+ if (reasoningParts.length) {
2774
+ parts.push(`## Reasoning
2775
+ ${reasoningParts.join("\n")}`);
2776
+ }
2777
+ }
2778
+ if (this._memory) {
2779
+ const memoryParts = [];
2780
+ if (this._memory.summary) {
2781
+ memoryParts.push(`Previous conversation summary: ${this._memory.summary}`);
2782
+ }
2783
+ if (this._memory.facts?.length) {
2784
+ memoryParts.push(`Known facts:
2785
+ ${this._memory.facts.map((f) => `- ${f}`).join("\n")}`);
2786
+ }
2787
+ if (this._memory.preferences?.length) {
2788
+ memoryParts.push(`User preferences:
2789
+ ${this._memory.preferences.map((p) => `- ${p}`).join("\n")}`);
2790
+ }
2791
+ if (memoryParts.length) {
2792
+ parts.push(`## Memory
2793
+ ${memoryParts.join("\n")}`);
2794
+ }
2795
+ }
2796
+ if (this._customSystemParts.length) {
2797
+ parts.push(...this._customSystemParts);
2798
+ }
2799
+ return parts.join("\n\n");
2800
+ }
2801
+ build() {
2802
+ const systemPrompt = this.buildSystemPrompt();
2803
+ let messages = [...this._messages];
2804
+ const hasSystemMessage = messages.some((m) => m.role === "system");
2805
+ if (systemPrompt && !hasSystemMessage) {
2806
+ messages = [{ role: "system", content: systemPrompt }, ...messages];
2807
+ } else if (systemPrompt && hasSystemMessage) {
2808
+ messages = messages.map(
2809
+ (m) => m.role === "system" ? { ...m, content: `${systemPrompt}
2810
+
2811
+ ${m.content}` } : m
2812
+ );
2813
+ }
2814
+ if (this._memory?.history) {
2815
+ const systemIdx = messages.findIndex((m) => m.role === "system");
2816
+ const insertIdx = systemIdx >= 0 ? systemIdx + 1 : 0;
2817
+ messages.splice(insertIdx, 0, ...this._memory.history);
2818
+ }
2819
+ const userMessages = messages.filter((m) => m.role === "user");
2820
+ const userPrompt = userMessages.length ? userMessages[userMessages.length - 1].content : void 0;
2821
+ return {
2822
+ messages,
2823
+ systemPrompt,
2824
+ userPrompt,
2825
+ metadata: {
2826
+ persona: this._persona,
2827
+ context: this._context,
2828
+ task: this._task,
2829
+ output: this._output,
2830
+ reasoning: this._reasoning,
2831
+ examples: this._examples.length ? this._examples : void 0
2832
+ }
2833
+ };
2834
+ }
2835
+ // --- Output Methods ---
2836
+ toString() {
2837
+ return this.buildSystemPrompt();
2838
+ }
2839
+ toSystemPrompt() {
2840
+ return this.buildSystemPrompt();
2841
+ }
2842
+ toMessages() {
2843
+ return this.build().messages;
2844
+ }
2845
+ toJSON() {
2846
+ return JSON.stringify(this.build(), null, 2);
2847
+ }
2848
+ toYAML() {
2849
+ return objectToYaml4(this.build());
2850
+ }
2851
+ toMarkdown() {
2852
+ const built = this.build();
2853
+ const sections = ["# Chat Prompt\n"];
2854
+ sections.push("## System Prompt\n```\n" + built.systemPrompt + "\n```\n");
2855
+ if (built.messages.length > 1) {
2856
+ sections.push("## Messages\n");
2857
+ for (const msg of built.messages) {
2858
+ if (msg.role === "system") continue;
2859
+ sections.push(`**${msg.role.toUpperCase()}${msg.name ? ` (${msg.name})` : ""}:**
2860
+ ${msg.content}
2861
+ `);
2862
+ }
2863
+ }
2864
+ return sections.join("\n");
2865
+ }
2866
+ };
2867
+ function objectToYaml4(obj, indent = 0) {
2868
+ const spaces = " ".repeat(indent);
2869
+ const lines = [];
2870
+ for (const [key, value] of Object.entries(obj)) {
2871
+ if (value === void 0 || value === null) continue;
2872
+ if (Array.isArray(value)) {
2873
+ if (value.length === 0) continue;
2874
+ lines.push(`${spaces}${key}:`);
2875
+ for (const item of value) {
2876
+ if (typeof item === "object") {
2877
+ lines.push(`${spaces} -`);
2878
+ lines.push(objectToYaml4(item, indent + 2).replace(/^/gm, " "));
2879
+ } else {
2880
+ lines.push(`${spaces} - ${item}`);
2881
+ }
2882
+ }
2883
+ } else if (typeof value === "object") {
2884
+ lines.push(`${spaces}${key}:`);
2885
+ lines.push(objectToYaml4(value, indent + 1));
2886
+ } else if (typeof value === "string" && value.includes("\n")) {
2887
+ lines.push(`${spaces}${key}: |`);
2888
+ for (const line of value.split("\n")) {
2889
+ lines.push(`${spaces} ${line}`);
2890
+ }
2891
+ } else {
2892
+ lines.push(`${spaces}${key}: ${value}`);
2893
+ }
2894
+ }
2895
+ return lines.join("\n");
2896
+ }
2897
+ function chat() {
2898
+ return new ChatPromptBuilder();
2899
+ }
2900
+ var chatPresets = {
2901
+ /**
2902
+ * Code assistant preset
2903
+ */
2904
+ coder: (language) => {
2905
+ const c = chat().role("expert software developer").expertise("coding").tone("technical");
2906
+ if (language) {
2907
+ c.context(`Programming language: ${language}`);
2908
+ }
2909
+ return c;
2910
+ },
2911
+ /**
2912
+ * Writing assistant preset
2913
+ */
2914
+ writer: (style) => {
2915
+ const c = chat().role("skilled writer and editor").expertise("writing");
2916
+ if (style) {
2917
+ c.tone(style === "creative" ? "creative" : style === "academic" ? "academic" : "professional");
2918
+ }
2919
+ return c;
2920
+ },
2921
+ /**
2922
+ * Teacher/tutor preset
2923
+ */
2924
+ tutor: (subject) => {
2925
+ const c = chat().role("patient and knowledgeable tutor").expertise("teaching").tone(["friendly", "empathetic"]).stepByStep().withExamples();
2926
+ if (subject) {
2927
+ c.domain(subject);
2928
+ }
2929
+ return c;
2930
+ },
2931
+ /**
2932
+ * Analyst preset
2933
+ */
2934
+ analyst: () => {
2935
+ return chat().role("data analyst and researcher").expertise("analysis").tone("analytical").chainOfThought().detailed().withSources();
2936
+ },
2937
+ /**
2938
+ * Socratic dialogue preset
2939
+ */
2940
+ socratic: () => {
2941
+ return chat().role("Socratic philosopher and teacher").tone("socratic").reasoning({ style: "deductive", showWork: true }).avoid(["Give direct answers", "Lecture", "Be condescending"]);
2942
+ },
2943
+ /**
2944
+ * Critic preset
2945
+ */
2946
+ critic: () => {
2947
+ return chat().role("constructive critic").tone(["analytical", "professional"]).devilsAdvocate().detailed().avoid(["Be harsh", "Dismiss ideas without explanation"]);
2948
+ },
2949
+ /**
2950
+ * Brainstormer preset
2951
+ */
2952
+ brainstormer: () => {
2953
+ return chat().role("creative brainstorming partner").tone(["creative", "encouraging"]).expertise("creative").considerAlternatives().avoid(["Dismiss ideas", "Be negative", "Limit creativity"]);
2954
+ },
2955
+ /**
2956
+ * JSON response preset
2957
+ */
2958
+ jsonResponder: (schemaName, schema) => {
2959
+ return chat().role("data processing assistant").tone("concise").jsonSchema(schemaName, schema).avoid(["Include markdown", "Add explanations outside JSON", "Include code fences"]);
2960
+ },
2961
+ /**
2962
+ * Summarizer preset
2963
+ */
2964
+ summarizer: (length = "brief") => {
2965
+ return chat().role("expert summarizer").expertise("analysis").tone("concise").length(length).task("Summarize the provided content, preserving key information");
2966
+ },
2967
+ /**
2968
+ * Translator preset
2969
+ */
2970
+ translator: (targetLanguage) => {
2971
+ return chat().role("professional translator").expertise("languages").responseLanguage(targetLanguage).avoid(["Add commentary", "Change meaning", "Omit content"]);
2972
+ }
2973
+ };
2974
+
2975
+ // src/builder/index.ts
2976
+ var PromptBuilder = class {
2977
+ constructor() {
2978
+ this._constraints = [];
2979
+ this._examples = [];
2980
+ this._variables = [];
2981
+ this._customSections = [];
2982
+ }
2983
+ /**
2984
+ * Set the role/persona for the AI
2985
+ */
2986
+ role(role) {
2987
+ this._role = role;
2988
+ return this;
2989
+ }
2990
+ /**
2991
+ * Alias for role()
2992
+ */
2993
+ persona(persona) {
2994
+ return this.role(persona);
2995
+ }
2996
+ /**
2997
+ * Set the context/background information
2998
+ */
2999
+ context(context) {
3000
+ this._context = context;
3001
+ return this;
3002
+ }
3003
+ /**
3004
+ * Alias for context()
3005
+ */
3006
+ background(background) {
3007
+ return this.context(background);
3008
+ }
3009
+ /**
3010
+ * Set the main task/instruction
3011
+ */
3012
+ task(task) {
3013
+ this._task = task;
3014
+ return this;
3015
+ }
3016
+ /**
3017
+ * Alias for task()
3018
+ */
3019
+ instruction(instruction) {
3020
+ return this.task(instruction);
3021
+ }
3022
+ /**
3023
+ * Add constraints/rules the AI should follow
3024
+ */
3025
+ constraints(constraints) {
3026
+ this._constraints = [...this._constraints, ...constraints];
3027
+ return this;
3028
+ }
3029
+ /**
3030
+ * Add a single constraint
3031
+ */
3032
+ constraint(constraint) {
3033
+ this._constraints.push(constraint);
3034
+ return this;
3035
+ }
3036
+ /**
3037
+ * Alias for constraints()
3038
+ */
3039
+ rules(rules) {
3040
+ return this.constraints(rules);
3041
+ }
3042
+ /**
3043
+ * Set the expected output format
3044
+ */
3045
+ output(format) {
3046
+ this._outputFormat = format;
3047
+ return this;
3048
+ }
3049
+ /**
3050
+ * Alias for output()
3051
+ */
3052
+ format(format) {
3053
+ return this.output(format);
3054
+ }
3055
+ /**
3056
+ * Add an example input/output pair
3057
+ */
3058
+ example(input, output) {
3059
+ this._examples.push({ input, output });
3060
+ return this;
3061
+ }
3062
+ /**
3063
+ * Add multiple examples
3064
+ */
3065
+ examples(examples) {
3066
+ this._examples = [...this._examples, ...examples];
3067
+ return this;
3068
+ }
3069
+ /**
3070
+ * Define a variable placeholder
3071
+ */
3072
+ variable(name, options = {}) {
3073
+ this._variables.push({
3074
+ name,
3075
+ description: options.description,
3076
+ required: options.required ?? true,
3077
+ defaultValue: options.defaultValue
3078
+ });
3079
+ return this;
3080
+ }
3081
+ /**
3082
+ * Add a custom section
3083
+ */
3084
+ section(title, content) {
3085
+ this._customSections.push({ title, content });
3086
+ return this;
3087
+ }
3088
+ /**
3089
+ * Set raw content (bypasses structured building)
3090
+ */
3091
+ raw(content) {
3092
+ this._rawContent = content;
3093
+ return this;
3094
+ }
3095
+ /**
3096
+ * Build the final prompt
3097
+ */
3098
+ build() {
3099
+ if (this._rawContent) {
3100
+ return {
3101
+ content: this._rawContent,
3102
+ variables: this._variables,
3103
+ metadata: {}
3104
+ };
3105
+ }
3106
+ const sections = [];
3107
+ if (this._role) {
3108
+ sections.push(`You are ${this._role}.`);
3109
+ }
3110
+ if (this._context) {
3111
+ sections.push(`
3112
+ ## Context
3113
+ ${this._context}`);
3114
+ }
3115
+ if (this._task) {
3116
+ sections.push(`
3117
+ ## Task
3118
+ ${this._task}`);
3119
+ }
3120
+ if (this._constraints.length > 0) {
3121
+ const constraintsList = this._constraints.map((c, i) => `${i + 1}. ${c}`).join("\n");
3122
+ sections.push(`
3123
+ ## Constraints
3124
+ ${constraintsList}`);
3125
+ }
3126
+ if (this._outputFormat) {
3127
+ sections.push(`
3128
+ ## Output Format
3129
+ ${this._outputFormat}`);
3130
+ }
3131
+ if (this._examples.length > 0) {
3132
+ const examplesText = this._examples.map((e, i) => `### Example ${i + 1}
3133
+ **Input:** ${e.input}
3134
+ **Output:** ${e.output}`).join("\n\n");
3135
+ sections.push(`
3136
+ ## Examples
3137
+ ${examplesText}`);
3138
+ }
3139
+ for (const section of this._customSections) {
3140
+ sections.push(`
3141
+ ## ${section.title}
3142
+ ${section.content}`);
3143
+ }
3144
+ if (this._variables.length > 0) {
3145
+ const varsText = this._variables.map((v) => {
3146
+ const placeholder = v.defaultValue ? `\${${v.name}:${v.defaultValue}}` : `\${${v.name}}`;
3147
+ const desc = v.description ? ` - ${v.description}` : "";
3148
+ const req = v.required ? " (required)" : " (optional)";
3149
+ return `- ${placeholder}${desc}${req}`;
3150
+ }).join("\n");
3151
+ sections.push(`
3152
+ ## Variables
3153
+ ${varsText}`);
3154
+ }
3155
+ return {
3156
+ content: sections.join("\n").trim(),
3157
+ variables: this._variables,
3158
+ metadata: {
3159
+ role: this._role,
3160
+ context: this._context,
3161
+ task: this._task,
3162
+ constraints: this._constraints.length > 0 ? this._constraints : void 0,
3163
+ outputFormat: this._outputFormat,
3164
+ examples: this._examples.length > 0 ? this._examples : void 0
3165
+ }
3166
+ };
3167
+ }
3168
+ /**
3169
+ * Build and return only the content string
3170
+ */
3171
+ toString() {
3172
+ return this.build().content;
3173
+ }
3174
+ };
3175
+ function builder() {
3176
+ return new PromptBuilder();
3177
+ }
3178
+ function fromPrompt(content) {
3179
+ return new PromptBuilder().raw(content);
3180
+ }
3181
+ var templates = {
3182
+ /**
3183
+ * Create a code review prompt
3184
+ */
3185
+ codeReview: (options = {}) => {
3186
+ const b = builder().role("expert code reviewer").task("Review the provided code and identify issues, improvements, and best practices.").variable("code", { required: true, description: "The code to review" });
3187
+ if (options.language) {
3188
+ b.context(`You are reviewing ${options.language} code.`);
3189
+ }
3190
+ if (options.focus && options.focus.length > 0) {
3191
+ b.constraints(options.focus.map((f) => `Focus on ${f}`));
3192
+ }
3193
+ return b.output("Provide a structured review with: issues found, suggestions, and overall assessment.");
3194
+ },
3195
+ /**
3196
+ * Create a translation prompt
3197
+ */
3198
+ translation: (from, to) => {
3199
+ return builder().role(`professional translator fluent in ${from} and ${to}`).task(`Translate the following text from ${from} to ${to}.`).constraints([
3200
+ "Maintain the original meaning and tone",
3201
+ "Use natural, idiomatic expressions in the target language",
3202
+ "Preserve formatting and structure"
3203
+ ]).variable("text", { required: true, description: "Text to translate" });
3204
+ },
3205
+ /**
3206
+ * Create a summarization prompt
3207
+ */
3208
+ summarize: (options = {}) => {
3209
+ const b = builder().role("expert summarizer").task("Summarize the following content concisely while preserving key information.").variable("content", { required: true, description: "Content to summarize" });
3210
+ if (options.maxLength) {
3211
+ b.constraint(`Keep the summary under ${options.maxLength} words`);
3212
+ }
3213
+ if (options.style === "bullet") {
3214
+ b.output("Provide the summary as bullet points");
3215
+ }
3216
+ return b;
3217
+ },
3218
+ /**
3219
+ * Create a Q&A prompt
3220
+ */
3221
+ qa: (context) => {
3222
+ const b = builder().role("helpful assistant").task("Answer the question based on the provided context.").variable("question", { required: true, description: "The question to answer" });
3223
+ if (context) {
3224
+ b.context(context);
3225
+ } else {
3226
+ b.variable("context", { required: false, description: "Additional context" });
3227
+ }
3228
+ return b.constraints([
3229
+ "Be accurate and concise",
3230
+ "If you don't know the answer, say so",
3231
+ "Cite relevant parts of the context if applicable"
3232
+ ]);
3233
+ }
3234
+ };
3235
+ export {
3236
+ AudioPromptBuilder,
3237
+ ChatPromptBuilder,
3238
+ ImagePromptBuilder,
3239
+ PromptBuilder,
3240
+ VideoPromptBuilder,
3241
+ audio,
3242
+ builder,
3243
+ calculateSimilarity,
3244
+ chat,
3245
+ chatPresets,
3246
+ check as checkQuality,
3247
+ compile,
3248
+ convertAllVariables,
3249
+ convertToSupportedFormat,
3250
+ deduplicate,
3251
+ detectVariables,
3252
+ detect as detectVars,
3253
+ extractVariables,
3254
+ findDuplicates,
3255
+ fromPrompt,
3256
+ getContentFingerprint,
3257
+ getSuggestions,
3258
+ getSystemPrompt,
3259
+ image,
3260
+ interpolate,
3261
+ isSimilarContent,
3262
+ isValid as isValidPrompt,
3263
+ normalizeContent,
3264
+ normalize as normalizeVariables,
3265
+ parse as parsePrompt,
3266
+ parser_exports as parser,
3267
+ quality_exports as quality,
3268
+ similarity_exports as similarity,
3269
+ templates,
3270
+ toJson,
3271
+ toYaml,
3272
+ validate as validatePrompt,
3273
+ variables_exports as variables,
3274
+ video
3275
+ };
3276
+ //# sourceMappingURL=index.mjs.map