prompts.chat 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +856 -0
- package/dist/builder/index.d.mts +1067 -0
- package/dist/builder/index.d.ts +1067 -0
- package/dist/builder/index.js +2471 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/index.mjs +2432 -0
- package/dist/builder/index.mjs.map +1 -0
- package/dist/index-BEIO8LCd.d.mts +61 -0
- package/dist/index-BEIO8LCd.d.ts +61 -0
- package/dist/index-CSHEKYfQ.d.mts +64 -0
- package/dist/index-CSHEKYfQ.d.ts +64 -0
- package/dist/index-D41E6D9X.d.mts +77 -0
- package/dist/index-D41E6D9X.d.ts +77 -0
- package/dist/index-DOz8zcA0.d.mts +68 -0
- package/dist/index-DOz8zcA0.d.ts +68 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3335 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3276 -0
- package/dist/index.mjs.map +1 -0
- package/dist/parser/index.d.mts +1 -0
- package/dist/parser/index.d.ts +1 -0
- package/dist/parser/index.js +288 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/index.mjs +259 -0
- package/dist/parser/index.mjs.map +1 -0
- package/dist/quality/index.d.mts +1 -0
- package/dist/quality/index.d.ts +1 -0
- package/dist/quality/index.js +212 -0
- package/dist/quality/index.js.map +1 -0
- package/dist/quality/index.mjs +184 -0
- package/dist/quality/index.mjs.map +1 -0
- package/dist/similarity/index.d.mts +1 -0
- package/dist/similarity/index.d.ts +1 -0
- package/dist/similarity/index.js +123 -0
- package/dist/similarity/index.js.map +1 -0
- package/dist/similarity/index.mjs +91 -0
- package/dist/similarity/index.mjs.map +1 -0
- package/dist/variables/index.d.mts +1 -0
- package/dist/variables/index.d.ts +1 -0
- package/dist/variables/index.js +306 -0
- package/dist/variables/index.js.map +1 -0
- package/dist/variables/index.mjs +274 -0
- package/dist/variables/index.mjs.map +1 -0
- package/package.json +77 -6
|
@@ -0,0 +1,2432 @@
|
|
|
1
|
+
// src/builder/media.ts
|
|
2
|
+
var ImagePromptBuilder = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this._negative = [];
|
|
5
|
+
this._custom = [];
|
|
6
|
+
}
|
|
7
|
+
// --- Subject Methods ---
|
|
8
|
+
subject(main) {
|
|
9
|
+
if (typeof main === "string") {
|
|
10
|
+
this._subject = { ...this._subject || {}, main };
|
|
11
|
+
} else {
|
|
12
|
+
this._subject = { ...this._subject || {}, ...main };
|
|
13
|
+
}
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
subjectDetails(details) {
|
|
17
|
+
this._subject = { ...this._subject || { main: "" }, details };
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
expression(expression) {
|
|
21
|
+
this._subject = { ...this._subject || { main: "" }, expression };
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
pose(pose) {
|
|
25
|
+
this._subject = { ...this._subject || { main: "" }, pose };
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
action(action) {
|
|
29
|
+
this._subject = { ...this._subject || { main: "" }, action };
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
clothing(clothing) {
|
|
33
|
+
this._subject = { ...this._subject || { main: "" }, clothing };
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
accessories(accessories) {
|
|
37
|
+
this._subject = { ...this._subject || { main: "" }, accessories };
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
subjectCount(count) {
|
|
41
|
+
this._subject = { ...this._subject || { main: "" }, count };
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
// --- Camera Methods ---
|
|
45
|
+
camera(settings) {
|
|
46
|
+
this._camera = { ...this._camera || {}, ...settings };
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
angle(angle) {
|
|
50
|
+
this._camera = { ...this._camera || {}, angle };
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
shot(shot) {
|
|
54
|
+
this._camera = { ...this._camera || {}, shot };
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
lens(lens) {
|
|
58
|
+
this._camera = { ...this._camera || {}, lens };
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
focus(focus) {
|
|
62
|
+
this._camera = { ...this._camera || {}, focus };
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
aperture(aperture) {
|
|
66
|
+
this._camera = { ...this._camera || {}, aperture };
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
filmStock(filmStock) {
|
|
70
|
+
this._camera = { ...this._camera || {}, filmStock };
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
filmFormat(format) {
|
|
74
|
+
this._camera = { ...this._camera || {}, filmFormat: format };
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
cameraBrand(brand) {
|
|
78
|
+
this._camera = { ...this._camera || {}, brand };
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
cameraModel(model) {
|
|
82
|
+
this._camera = { ...this._camera || {}, model };
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
sensor(sensor) {
|
|
86
|
+
this._camera = { ...this._camera || {}, sensor };
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
lensModel(model) {
|
|
90
|
+
this._camera = { ...this._camera || {}, lensModel: model };
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
lensBrand(brand) {
|
|
94
|
+
this._camera = { ...this._camera || {}, lensBrand: brand };
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
focalLength(length) {
|
|
98
|
+
this._camera = { ...this._camera || {}, focalLength: length };
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
bokeh(style) {
|
|
102
|
+
this._camera = { ...this._camera || {}, bokeh: style };
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
filter(filter) {
|
|
106
|
+
this._camera = { ...this._camera || {}, filter };
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
iso(iso) {
|
|
110
|
+
this._camera = { ...this._camera || {}, iso };
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
shutterSpeed(speed) {
|
|
114
|
+
this._camera = { ...this._camera || {}, shutterSpeed: speed };
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
whiteBalance(wb) {
|
|
118
|
+
this._camera = { ...this._camera || {}, whiteBalance: wb };
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
colorProfile(profile) {
|
|
122
|
+
this._camera = { ...this._camera || {}, colorProfile: profile };
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
// --- Lighting Methods ---
|
|
126
|
+
lighting(settings) {
|
|
127
|
+
this._lighting = { ...this._lighting || {}, ...settings };
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
lightingType(type) {
|
|
131
|
+
this._lighting = { ...this._lighting || {}, type };
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
timeOfDay(time) {
|
|
135
|
+
this._lighting = { ...this._lighting || {}, time };
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
weather(weather) {
|
|
139
|
+
this._lighting = { ...this._lighting || {}, weather };
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
lightDirection(direction) {
|
|
143
|
+
this._lighting = { ...this._lighting || {}, direction };
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
lightIntensity(intensity) {
|
|
147
|
+
this._lighting = { ...this._lighting || {}, intensity };
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
// --- Composition Methods ---
|
|
151
|
+
composition(settings) {
|
|
152
|
+
this._composition = { ...this._composition || {}, ...settings };
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
ruleOfThirds() {
|
|
156
|
+
this._composition = { ...this._composition || {}, ruleOfThirds: true };
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
goldenRatio() {
|
|
160
|
+
this._composition = { ...this._composition || {}, goldenRatio: true };
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
symmetry(type) {
|
|
164
|
+
this._composition = { ...this._composition || {}, symmetry: type };
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
foreground(fg) {
|
|
168
|
+
this._composition = { ...this._composition || {}, foreground: fg };
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
midground(mg) {
|
|
172
|
+
this._composition = { ...this._composition || {}, midground: mg };
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
background(bg) {
|
|
176
|
+
this._composition = { ...this._composition || {}, background: bg };
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
// --- Environment Methods ---
|
|
180
|
+
environment(setting) {
|
|
181
|
+
if (typeof setting === "string") {
|
|
182
|
+
this._environment = { ...this._environment || { setting: "" }, setting };
|
|
183
|
+
} else {
|
|
184
|
+
this._environment = { ...this._environment || { setting: "" }, ...setting };
|
|
185
|
+
}
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
location(location) {
|
|
189
|
+
this._environment = { ...this._environment || { setting: "" }, location };
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
props(props) {
|
|
193
|
+
this._environment = { ...this._environment || { setting: "" }, props };
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
atmosphere(atmosphere) {
|
|
197
|
+
this._environment = { ...this._environment || { setting: "" }, atmosphere };
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
season(season) {
|
|
201
|
+
this._environment = { ...this._environment || { setting: "" }, season };
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
// --- Style Methods ---
|
|
205
|
+
style(settings) {
|
|
206
|
+
this._style = { ...this._style || {}, ...settings };
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
medium(medium) {
|
|
210
|
+
this._style = { ...this._style || {}, medium };
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
artist(artist) {
|
|
214
|
+
this._style = { ...this._style || {}, artist };
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
influence(influences) {
|
|
218
|
+
this._style = { ...this._style || {}, influence: influences };
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
// --- Color Methods ---
|
|
222
|
+
color(settings) {
|
|
223
|
+
this._color = { ...this._color || {}, ...settings };
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
palette(palette) {
|
|
227
|
+
this._color = { ...this._color || {}, palette };
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
primaryColors(colors) {
|
|
231
|
+
this._color = { ...this._color || {}, primary: colors };
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
accentColors(colors) {
|
|
235
|
+
this._color = { ...this._color || {}, accent: colors };
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
colorGrade(grade) {
|
|
239
|
+
this._color = { ...this._color || {}, grade };
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
// --- Technical Methods ---
|
|
243
|
+
technical(settings) {
|
|
244
|
+
this._technical = { ...this._technical || {}, ...settings };
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
aspectRatio(ratio) {
|
|
248
|
+
this._technical = { ...this._technical || {}, aspectRatio: ratio };
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
resolution(resolution) {
|
|
252
|
+
this._technical = { ...this._technical || {}, resolution };
|
|
253
|
+
return this;
|
|
254
|
+
}
|
|
255
|
+
quality(quality) {
|
|
256
|
+
this._technical = { ...this._technical || {}, quality };
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
// --- Mood & Misc ---
|
|
260
|
+
mood(mood) {
|
|
261
|
+
this._mood = mood;
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
negative(items) {
|
|
265
|
+
this._negative = [...this._negative, ...items];
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
custom(text) {
|
|
269
|
+
this._custom.push(text);
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
// --- Build Methods ---
|
|
273
|
+
buildPromptText() {
|
|
274
|
+
const parts = [];
|
|
275
|
+
if (this._subject) {
|
|
276
|
+
let subjectText = this._subject.main;
|
|
277
|
+
if (this._subject.count && this._subject.count !== "single") {
|
|
278
|
+
subjectText = `${this._subject.count} ${subjectText}`;
|
|
279
|
+
}
|
|
280
|
+
if (this._subject.expression) subjectText += `, ${this._subject.expression} expression`;
|
|
281
|
+
if (this._subject.pose) subjectText += `, ${this._subject.pose}`;
|
|
282
|
+
if (this._subject.action) subjectText += `, ${this._subject.action}`;
|
|
283
|
+
if (this._subject.clothing) subjectText += `, wearing ${this._subject.clothing}`;
|
|
284
|
+
if (this._subject.accessories?.length) subjectText += `, with ${this._subject.accessories.join(", ")}`;
|
|
285
|
+
if (this._subject.details?.length) subjectText += `, ${this._subject.details.join(", ")}`;
|
|
286
|
+
parts.push(subjectText);
|
|
287
|
+
}
|
|
288
|
+
if (this._environment) {
|
|
289
|
+
let envText = this._environment.setting;
|
|
290
|
+
if (this._environment.location) envText += ` in ${this._environment.location}`;
|
|
291
|
+
if (this._environment.atmosphere) envText += `, ${this._environment.atmosphere} atmosphere`;
|
|
292
|
+
if (this._environment.season) envText += `, ${this._environment.season}`;
|
|
293
|
+
if (this._environment.props?.length) envText += `, with ${this._environment.props.join(", ")}`;
|
|
294
|
+
parts.push(envText);
|
|
295
|
+
}
|
|
296
|
+
if (this._composition) {
|
|
297
|
+
const compParts = [];
|
|
298
|
+
if (this._composition.foreground) compParts.push(`foreground: ${this._composition.foreground}`);
|
|
299
|
+
if (this._composition.midground) compParts.push(`midground: ${this._composition.midground}`);
|
|
300
|
+
if (this._composition.background) compParts.push(`background: ${this._composition.background}`);
|
|
301
|
+
if (this._composition.ruleOfThirds) compParts.push("rule of thirds composition");
|
|
302
|
+
if (this._composition.goldenRatio) compParts.push("golden ratio composition");
|
|
303
|
+
if (this._composition.symmetry && this._composition.symmetry !== "none") {
|
|
304
|
+
compParts.push(`${this._composition.symmetry} symmetry`);
|
|
305
|
+
}
|
|
306
|
+
if (compParts.length) parts.push(compParts.join(", "));
|
|
307
|
+
}
|
|
308
|
+
if (this._camera) {
|
|
309
|
+
const camParts = [];
|
|
310
|
+
if (this._camera.shot) camParts.push(`${this._camera.shot} shot`);
|
|
311
|
+
if (this._camera.angle) camParts.push(`${this._camera.angle}`);
|
|
312
|
+
if (this._camera.lens) camParts.push(`${this._camera.lens} lens`);
|
|
313
|
+
if (this._camera.focus) camParts.push(`${this._camera.focus} depth of field`);
|
|
314
|
+
if (this._camera.aperture) camParts.push(`f/${this._camera.aperture}`);
|
|
315
|
+
if (this._camera.filmStock) camParts.push(`shot on ${this._camera.filmStock}`);
|
|
316
|
+
if (this._camera.brand) camParts.push(`${this._camera.brand}`);
|
|
317
|
+
if (camParts.length) parts.push(camParts.join(", "));
|
|
318
|
+
}
|
|
319
|
+
if (this._lighting) {
|
|
320
|
+
const lightParts = [];
|
|
321
|
+
if (this._lighting.type) {
|
|
322
|
+
const types = Array.isArray(this._lighting.type) ? this._lighting.type : [this._lighting.type];
|
|
323
|
+
lightParts.push(`${types.join(" and ")} lighting`);
|
|
324
|
+
}
|
|
325
|
+
if (this._lighting.time) lightParts.push(this._lighting.time);
|
|
326
|
+
if (this._lighting.weather) lightParts.push(`${this._lighting.weather} weather`);
|
|
327
|
+
if (this._lighting.direction) lightParts.push(`light from ${this._lighting.direction}`);
|
|
328
|
+
if (this._lighting.intensity) lightParts.push(`${this._lighting.intensity} light`);
|
|
329
|
+
if (lightParts.length) parts.push(lightParts.join(", "));
|
|
330
|
+
}
|
|
331
|
+
if (this._style) {
|
|
332
|
+
const styleParts = [];
|
|
333
|
+
if (this._style.medium) {
|
|
334
|
+
const mediums = Array.isArray(this._style.medium) ? this._style.medium : [this._style.medium];
|
|
335
|
+
styleParts.push(mediums.join(", "));
|
|
336
|
+
}
|
|
337
|
+
if (this._style.artist) {
|
|
338
|
+
const artists = Array.isArray(this._style.artist) ? this._style.artist : [this._style.artist];
|
|
339
|
+
styleParts.push(`in the style of ${artists.join(" and ")}`);
|
|
340
|
+
}
|
|
341
|
+
if (this._style.era) styleParts.push(this._style.era);
|
|
342
|
+
if (this._style.influence?.length) styleParts.push(`influenced by ${this._style.influence.join(", ")}`);
|
|
343
|
+
if (this._style.quality?.length) styleParts.push(this._style.quality.join(", "));
|
|
344
|
+
if (styleParts.length) parts.push(styleParts.join(", "));
|
|
345
|
+
}
|
|
346
|
+
if (this._color) {
|
|
347
|
+
const colorParts = [];
|
|
348
|
+
if (this._color.palette) {
|
|
349
|
+
const palettes = Array.isArray(this._color.palette) ? this._color.palette : [this._color.palette];
|
|
350
|
+
colorParts.push(`${palettes.join(" and ")} color palette`);
|
|
351
|
+
}
|
|
352
|
+
if (this._color.primary?.length) colorParts.push(`primary colors: ${this._color.primary.join(", ")}`);
|
|
353
|
+
if (this._color.accent?.length) colorParts.push(`accent colors: ${this._color.accent.join(", ")}`);
|
|
354
|
+
if (this._color.grade) colorParts.push(`${this._color.grade} color grade`);
|
|
355
|
+
if (this._color.temperature) colorParts.push(`${this._color.temperature} tones`);
|
|
356
|
+
if (colorParts.length) parts.push(colorParts.join(", "));
|
|
357
|
+
}
|
|
358
|
+
if (this._mood) {
|
|
359
|
+
const moods = Array.isArray(this._mood) ? this._mood : [this._mood];
|
|
360
|
+
parts.push(`${moods.join(", ")} mood`);
|
|
361
|
+
}
|
|
362
|
+
if (this._technical) {
|
|
363
|
+
const techParts = [];
|
|
364
|
+
if (this._technical.quality) techParts.push(`${this._technical.quality} quality`);
|
|
365
|
+
if (this._technical.detail) techParts.push(`${this._technical.detail} detail`);
|
|
366
|
+
if (this._technical.resolution) techParts.push(this._technical.resolution);
|
|
367
|
+
if (techParts.length) parts.push(techParts.join(", "));
|
|
368
|
+
}
|
|
369
|
+
if (this._custom.length) {
|
|
370
|
+
parts.push(this._custom.join(", "));
|
|
371
|
+
}
|
|
372
|
+
let prompt = parts.join(", ");
|
|
373
|
+
if (this._negative.length) {
|
|
374
|
+
prompt += ` --no ${this._negative.join(", ")}`;
|
|
375
|
+
}
|
|
376
|
+
if (this._technical?.aspectRatio) {
|
|
377
|
+
prompt += ` --ar ${this._technical.aspectRatio}`;
|
|
378
|
+
}
|
|
379
|
+
return prompt;
|
|
380
|
+
}
|
|
381
|
+
build() {
|
|
382
|
+
return {
|
|
383
|
+
prompt: this.buildPromptText(),
|
|
384
|
+
structure: {
|
|
385
|
+
subject: this._subject,
|
|
386
|
+
camera: this._camera,
|
|
387
|
+
lighting: this._lighting,
|
|
388
|
+
composition: this._composition,
|
|
389
|
+
style: this._style,
|
|
390
|
+
color: this._color,
|
|
391
|
+
environment: this._environment,
|
|
392
|
+
technical: this._technical,
|
|
393
|
+
mood: this._mood,
|
|
394
|
+
negative: this._negative.length ? this._negative : void 0
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
toString() {
|
|
399
|
+
return this.build().prompt;
|
|
400
|
+
}
|
|
401
|
+
toJSON() {
|
|
402
|
+
return JSON.stringify(this.build().structure, null, 2);
|
|
403
|
+
}
|
|
404
|
+
toYAML() {
|
|
405
|
+
return objectToYaml(this.build().structure);
|
|
406
|
+
}
|
|
407
|
+
toMarkdown() {
|
|
408
|
+
const built = this.build();
|
|
409
|
+
const sections = ["# Image Prompt\n"];
|
|
410
|
+
sections.push("## Prompt\n```\n" + built.prompt + "\n```\n");
|
|
411
|
+
if (built.structure.subject) {
|
|
412
|
+
sections.push("## Subject\n" + objectToMarkdownList(built.structure.subject));
|
|
413
|
+
}
|
|
414
|
+
if (built.structure.environment) {
|
|
415
|
+
sections.push("## Environment\n" + objectToMarkdownList(built.structure.environment));
|
|
416
|
+
}
|
|
417
|
+
if (built.structure.camera) {
|
|
418
|
+
sections.push("## Camera\n" + objectToMarkdownList(built.structure.camera));
|
|
419
|
+
}
|
|
420
|
+
if (built.structure.lighting) {
|
|
421
|
+
sections.push("## Lighting\n" + objectToMarkdownList(built.structure.lighting));
|
|
422
|
+
}
|
|
423
|
+
if (built.structure.composition) {
|
|
424
|
+
sections.push("## Composition\n" + objectToMarkdownList(built.structure.composition));
|
|
425
|
+
}
|
|
426
|
+
if (built.structure.style) {
|
|
427
|
+
sections.push("## Style\n" + objectToMarkdownList(built.structure.style));
|
|
428
|
+
}
|
|
429
|
+
if (built.structure.color) {
|
|
430
|
+
sections.push("## Color\n" + objectToMarkdownList(built.structure.color));
|
|
431
|
+
}
|
|
432
|
+
if (built.structure.technical) {
|
|
433
|
+
sections.push("## Technical\n" + objectToMarkdownList(built.structure.technical));
|
|
434
|
+
}
|
|
435
|
+
return sections.join("\n");
|
|
436
|
+
}
|
|
437
|
+
format(fmt) {
|
|
438
|
+
switch (fmt) {
|
|
439
|
+
case "json":
|
|
440
|
+
return this.toJSON();
|
|
441
|
+
case "yaml":
|
|
442
|
+
return this.toYAML();
|
|
443
|
+
case "markdown":
|
|
444
|
+
return this.toMarkdown();
|
|
445
|
+
default:
|
|
446
|
+
return this.toString();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
function objectToYaml(obj, indent = 0) {
|
|
451
|
+
const spaces = " ".repeat(indent);
|
|
452
|
+
const lines = [];
|
|
453
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
454
|
+
if (value === void 0 || value === null) continue;
|
|
455
|
+
if (Array.isArray(value)) {
|
|
456
|
+
if (value.length === 0) continue;
|
|
457
|
+
lines.push(`${spaces}${key}:`);
|
|
458
|
+
for (const item of value) {
|
|
459
|
+
if (typeof item === "object") {
|
|
460
|
+
lines.push(`${spaces} -`);
|
|
461
|
+
lines.push(objectToYaml(item, indent + 2).replace(/^/gm, " "));
|
|
462
|
+
} else {
|
|
463
|
+
lines.push(`${spaces} - ${item}`);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
} else if (typeof value === "object") {
|
|
467
|
+
lines.push(`${spaces}${key}:`);
|
|
468
|
+
lines.push(objectToYaml(value, indent + 1));
|
|
469
|
+
} else {
|
|
470
|
+
lines.push(`${spaces}${key}: ${value}`);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return lines.join("\n");
|
|
474
|
+
}
|
|
475
|
+
function objectToMarkdownList(obj, indent = 0) {
|
|
476
|
+
const spaces = " ".repeat(indent);
|
|
477
|
+
const lines = [];
|
|
478
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
479
|
+
if (value === void 0 || value === null) continue;
|
|
480
|
+
if (Array.isArray(value)) {
|
|
481
|
+
lines.push(`${spaces}- **${key}:** ${value.join(", ")}`);
|
|
482
|
+
} else if (typeof value === "object") {
|
|
483
|
+
lines.push(`${spaces}- **${key}:**`);
|
|
484
|
+
lines.push(objectToMarkdownList(value, indent + 1));
|
|
485
|
+
} else {
|
|
486
|
+
lines.push(`${spaces}- **${key}:** ${value}`);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return lines.join("\n");
|
|
490
|
+
}
|
|
491
|
+
function image() {
|
|
492
|
+
return new ImagePromptBuilder();
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// src/builder/video.ts
|
|
496
|
+
var VideoPromptBuilder = class {
|
|
497
|
+
constructor() {
|
|
498
|
+
this._actions = [];
|
|
499
|
+
this._shots = [];
|
|
500
|
+
this._transitions = [];
|
|
501
|
+
this._custom = [];
|
|
502
|
+
}
|
|
503
|
+
// --- Scene Methods ---
|
|
504
|
+
scene(description) {
|
|
505
|
+
if (typeof description === "string") {
|
|
506
|
+
this._scene = { ...this._scene || { description: "" }, description };
|
|
507
|
+
} else {
|
|
508
|
+
this._scene = { ...this._scene || { description: "" }, ...description };
|
|
509
|
+
}
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
512
|
+
setting(setting) {
|
|
513
|
+
this._scene = { ...this._scene || { description: "" }, setting };
|
|
514
|
+
return this;
|
|
515
|
+
}
|
|
516
|
+
// --- Subject Methods ---
|
|
517
|
+
subject(main) {
|
|
518
|
+
if (typeof main === "string") {
|
|
519
|
+
this._subject = { ...this._subject || { main: "" }, main };
|
|
520
|
+
} else {
|
|
521
|
+
this._subject = { ...this._subject || { main: "" }, ...main };
|
|
522
|
+
}
|
|
523
|
+
return this;
|
|
524
|
+
}
|
|
525
|
+
appearance(appearance) {
|
|
526
|
+
this._subject = { ...this._subject || { main: "" }, appearance };
|
|
527
|
+
return this;
|
|
528
|
+
}
|
|
529
|
+
clothing(clothing) {
|
|
530
|
+
this._subject = { ...this._subject || { main: "" }, clothing };
|
|
531
|
+
return this;
|
|
532
|
+
}
|
|
533
|
+
// --- Camera Methods ---
|
|
534
|
+
camera(settings) {
|
|
535
|
+
this._camera = { ...this._camera || {}, ...settings };
|
|
536
|
+
return this;
|
|
537
|
+
}
|
|
538
|
+
shot(shot) {
|
|
539
|
+
this._camera = { ...this._camera || {}, shot };
|
|
540
|
+
return this;
|
|
541
|
+
}
|
|
542
|
+
angle(angle) {
|
|
543
|
+
this._camera = { ...this._camera || {}, angle };
|
|
544
|
+
return this;
|
|
545
|
+
}
|
|
546
|
+
movement(movement) {
|
|
547
|
+
this._camera = { ...this._camera || {}, movement };
|
|
548
|
+
return this;
|
|
549
|
+
}
|
|
550
|
+
lens(lens) {
|
|
551
|
+
this._camera = { ...this._camera || {}, lens };
|
|
552
|
+
return this;
|
|
553
|
+
}
|
|
554
|
+
platform(platform) {
|
|
555
|
+
this._camera = { ...this._camera || {}, platform };
|
|
556
|
+
return this;
|
|
557
|
+
}
|
|
558
|
+
cameraSpeed(speed) {
|
|
559
|
+
this._camera = { ...this._camera || {}, movementSpeed: speed };
|
|
560
|
+
return this;
|
|
561
|
+
}
|
|
562
|
+
movementDirection(direction) {
|
|
563
|
+
this._camera = { ...this._camera || {}, movementDirection: direction };
|
|
564
|
+
return this;
|
|
565
|
+
}
|
|
566
|
+
rig(rig) {
|
|
567
|
+
this._camera = { ...this._camera || {}, rig };
|
|
568
|
+
return this;
|
|
569
|
+
}
|
|
570
|
+
gimbal(gimbal) {
|
|
571
|
+
this._camera = { ...this._camera || {}, gimbal };
|
|
572
|
+
return this;
|
|
573
|
+
}
|
|
574
|
+
cameraBrand(brand) {
|
|
575
|
+
this._camera = { ...this._camera || {}, brand };
|
|
576
|
+
return this;
|
|
577
|
+
}
|
|
578
|
+
cameraModel(model) {
|
|
579
|
+
this._camera = { ...this._camera || {}, model };
|
|
580
|
+
return this;
|
|
581
|
+
}
|
|
582
|
+
sensor(sensor) {
|
|
583
|
+
this._camera = { ...this._camera || {}, sensor };
|
|
584
|
+
return this;
|
|
585
|
+
}
|
|
586
|
+
lensModel(model) {
|
|
587
|
+
this._camera = { ...this._camera || {}, lensModel: model };
|
|
588
|
+
return this;
|
|
589
|
+
}
|
|
590
|
+
lensBrand(brand) {
|
|
591
|
+
this._camera = { ...this._camera || {}, lensBrand: brand };
|
|
592
|
+
return this;
|
|
593
|
+
}
|
|
594
|
+
focalLength(length) {
|
|
595
|
+
this._camera = { ...this._camera || {}, focalLength: length };
|
|
596
|
+
return this;
|
|
597
|
+
}
|
|
598
|
+
anamorphic(ratio) {
|
|
599
|
+
this._camera = { ...this._camera || {}, anamorphic: true, anamorphicRatio: ratio };
|
|
600
|
+
return this;
|
|
601
|
+
}
|
|
602
|
+
aperture(aperture) {
|
|
603
|
+
this._camera = { ...this._camera || {}, aperture };
|
|
604
|
+
return this;
|
|
605
|
+
}
|
|
606
|
+
frameRate(fps) {
|
|
607
|
+
this._camera = { ...this._camera || {}, frameRate: fps };
|
|
608
|
+
return this;
|
|
609
|
+
}
|
|
610
|
+
slowMotion(enabled = true) {
|
|
611
|
+
this._camera = { ...this._camera || {}, slowMotion: enabled };
|
|
612
|
+
return this;
|
|
613
|
+
}
|
|
614
|
+
shutterAngle(angle) {
|
|
615
|
+
this._camera = { ...this._camera || {}, shutterAngle: angle };
|
|
616
|
+
return this;
|
|
617
|
+
}
|
|
618
|
+
filter(filter) {
|
|
619
|
+
this._camera = { ...this._camera || {}, filter };
|
|
620
|
+
return this;
|
|
621
|
+
}
|
|
622
|
+
filmStock(stock) {
|
|
623
|
+
this._camera = { ...this._camera || {}, filmStock: stock };
|
|
624
|
+
return this;
|
|
625
|
+
}
|
|
626
|
+
filmGrain(grain) {
|
|
627
|
+
this._camera = { ...this._camera || {}, filmGrain: grain };
|
|
628
|
+
return this;
|
|
629
|
+
}
|
|
630
|
+
halation(enabled = true) {
|
|
631
|
+
this._camera = { ...this._camera || {}, halation: enabled };
|
|
632
|
+
return this;
|
|
633
|
+
}
|
|
634
|
+
// --- Lighting Methods ---
|
|
635
|
+
lighting(settings) {
|
|
636
|
+
this._lighting = { ...this._lighting || {}, ...settings };
|
|
637
|
+
return this;
|
|
638
|
+
}
|
|
639
|
+
lightingType(type) {
|
|
640
|
+
this._lighting = { ...this._lighting || {}, type };
|
|
641
|
+
return this;
|
|
642
|
+
}
|
|
643
|
+
timeOfDay(time) {
|
|
644
|
+
this._lighting = { ...this._lighting || {}, time };
|
|
645
|
+
this._scene = { ...this._scene || { description: "" }, timeOfDay: time };
|
|
646
|
+
return this;
|
|
647
|
+
}
|
|
648
|
+
weather(weather) {
|
|
649
|
+
this._lighting = { ...this._lighting || {}, weather };
|
|
650
|
+
this._scene = { ...this._scene || { description: "" }, weather };
|
|
651
|
+
return this;
|
|
652
|
+
}
|
|
653
|
+
// --- Action & Motion Methods ---
|
|
654
|
+
action(action, options = {}) {
|
|
655
|
+
this._actions.push({
|
|
656
|
+
beat: this._actions.length + 1,
|
|
657
|
+
action,
|
|
658
|
+
...options
|
|
659
|
+
});
|
|
660
|
+
return this;
|
|
661
|
+
}
|
|
662
|
+
actions(actions) {
|
|
663
|
+
actions.forEach((a, i) => this._actions.push({ beat: i + 1, action: a }));
|
|
664
|
+
return this;
|
|
665
|
+
}
|
|
666
|
+
motion(settings) {
|
|
667
|
+
this._motion = { ...this._motion || {}, ...settings };
|
|
668
|
+
return this;
|
|
669
|
+
}
|
|
670
|
+
motionBeats(beats) {
|
|
671
|
+
this._motion = { ...this._motion || {}, beats };
|
|
672
|
+
return this;
|
|
673
|
+
}
|
|
674
|
+
// --- Style Methods ---
|
|
675
|
+
style(settings) {
|
|
676
|
+
this._style = { ...this._style || {}, ...settings };
|
|
677
|
+
return this;
|
|
678
|
+
}
|
|
679
|
+
format(format) {
|
|
680
|
+
this._style = { ...this._style || {}, format };
|
|
681
|
+
return this;
|
|
682
|
+
}
|
|
683
|
+
era(era) {
|
|
684
|
+
this._style = { ...this._style || {}, era };
|
|
685
|
+
return this;
|
|
686
|
+
}
|
|
687
|
+
styleFilmStock(stock) {
|
|
688
|
+
this._style = { ...this._style || {}, filmStock: stock };
|
|
689
|
+
return this;
|
|
690
|
+
}
|
|
691
|
+
look(look) {
|
|
692
|
+
this._style = { ...this._style || {}, look };
|
|
693
|
+
return this;
|
|
694
|
+
}
|
|
695
|
+
reference(references) {
|
|
696
|
+
this._style = { ...this._style || {}, reference: references };
|
|
697
|
+
return this;
|
|
698
|
+
}
|
|
699
|
+
// --- Color Methods ---
|
|
700
|
+
color(settings) {
|
|
701
|
+
this._color = { ...this._color || {}, ...settings };
|
|
702
|
+
return this;
|
|
703
|
+
}
|
|
704
|
+
palette(palette) {
|
|
705
|
+
this._color = { ...this._color || {}, palette };
|
|
706
|
+
return this;
|
|
707
|
+
}
|
|
708
|
+
colorAnchors(anchors) {
|
|
709
|
+
this._color = { ...this._color || {}, anchors };
|
|
710
|
+
return this;
|
|
711
|
+
}
|
|
712
|
+
colorGrade(grade) {
|
|
713
|
+
this._color = { ...this._color || {}, grade };
|
|
714
|
+
return this;
|
|
715
|
+
}
|
|
716
|
+
// --- Audio Methods ---
|
|
717
|
+
audio(settings) {
|
|
718
|
+
this._audio = { ...this._audio || {}, ...settings };
|
|
719
|
+
return this;
|
|
720
|
+
}
|
|
721
|
+
dialogue(dialogue) {
|
|
722
|
+
this._audio = { ...this._audio || {}, dialogue };
|
|
723
|
+
return this;
|
|
724
|
+
}
|
|
725
|
+
ambient(ambient) {
|
|
726
|
+
this._audio = { ...this._audio || {}, ambient };
|
|
727
|
+
return this;
|
|
728
|
+
}
|
|
729
|
+
diegetic(sounds) {
|
|
730
|
+
this._audio = { ...this._audio || {}, diegetic: sounds };
|
|
731
|
+
return this;
|
|
732
|
+
}
|
|
733
|
+
soundEffects(effects) {
|
|
734
|
+
this._audio = { ...this._audio || {}, soundEffects: effects };
|
|
735
|
+
return this;
|
|
736
|
+
}
|
|
737
|
+
music(music) {
|
|
738
|
+
this._audio = { ...this._audio || {}, music };
|
|
739
|
+
return this;
|
|
740
|
+
}
|
|
741
|
+
// --- Technical Methods ---
|
|
742
|
+
technical(settings) {
|
|
743
|
+
this._technical = { ...this._technical || {}, ...settings };
|
|
744
|
+
return this;
|
|
745
|
+
}
|
|
746
|
+
duration(seconds) {
|
|
747
|
+
this._technical = { ...this._technical || {}, duration: seconds };
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
resolution(res) {
|
|
751
|
+
this._technical = { ...this._technical || {}, resolution: res };
|
|
752
|
+
return this;
|
|
753
|
+
}
|
|
754
|
+
fps(fps) {
|
|
755
|
+
this._technical = { ...this._technical || {}, fps };
|
|
756
|
+
return this;
|
|
757
|
+
}
|
|
758
|
+
aspectRatio(ratio) {
|
|
759
|
+
this._technical = { ...this._technical || {}, aspectRatio: ratio };
|
|
760
|
+
return this;
|
|
761
|
+
}
|
|
762
|
+
// --- Shot List Methods ---
|
|
763
|
+
addShot(shot) {
|
|
764
|
+
this._shots.push(shot);
|
|
765
|
+
return this;
|
|
766
|
+
}
|
|
767
|
+
shotList(shots) {
|
|
768
|
+
this._shots = [...this._shots, ...shots];
|
|
769
|
+
return this;
|
|
770
|
+
}
|
|
771
|
+
// --- Mood & Pacing ---
|
|
772
|
+
mood(mood) {
|
|
773
|
+
this._mood = mood;
|
|
774
|
+
return this;
|
|
775
|
+
}
|
|
776
|
+
pacing(pacing) {
|
|
777
|
+
this._pacing = pacing;
|
|
778
|
+
return this;
|
|
779
|
+
}
|
|
780
|
+
transition(transition) {
|
|
781
|
+
this._transitions.push(transition);
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
transitions(transitions) {
|
|
785
|
+
this._transitions = [...this._transitions, ...transitions];
|
|
786
|
+
return this;
|
|
787
|
+
}
|
|
788
|
+
custom(text) {
|
|
789
|
+
this._custom.push(text);
|
|
790
|
+
return this;
|
|
791
|
+
}
|
|
792
|
+
// --- Build Methods ---
|
|
793
|
+
buildPromptText() {
|
|
794
|
+
const sections = [];
|
|
795
|
+
if (this._scene) {
|
|
796
|
+
let sceneText = this._scene.description;
|
|
797
|
+
if (this._scene.setting) sceneText = `${this._scene.setting}. ${sceneText}`;
|
|
798
|
+
if (this._scene.atmosphere) sceneText += `, ${this._scene.atmosphere} atmosphere`;
|
|
799
|
+
sections.push(sceneText);
|
|
800
|
+
}
|
|
801
|
+
if (this._subject) {
|
|
802
|
+
let subjectText = this._subject.main;
|
|
803
|
+
if (this._subject.appearance) subjectText += `, ${this._subject.appearance}`;
|
|
804
|
+
if (this._subject.clothing) subjectText += `, wearing ${this._subject.clothing}`;
|
|
805
|
+
sections.push(subjectText);
|
|
806
|
+
}
|
|
807
|
+
const cinematography = [];
|
|
808
|
+
if (this._camera) {
|
|
809
|
+
if (this._camera.shot) cinematography.push(`${this._camera.shot} shot`);
|
|
810
|
+
if (this._camera.angle) cinematography.push(this._camera.angle);
|
|
811
|
+
if (this._camera.movement) cinematography.push(`${this._camera.movement} camera`);
|
|
812
|
+
if (this._camera.lens) cinematography.push(`${this._camera.lens} lens`);
|
|
813
|
+
if (this._camera.platform) cinematography.push(this._camera.platform);
|
|
814
|
+
if (this._camera.focus) cinematography.push(`${this._camera.focus} focus`);
|
|
815
|
+
}
|
|
816
|
+
if (cinematography.length) {
|
|
817
|
+
sections.push(`Cinematography: ${cinematography.join(", ")}`);
|
|
818
|
+
}
|
|
819
|
+
if (this._lighting) {
|
|
820
|
+
const lightParts = [];
|
|
821
|
+
if (this._lighting.type) {
|
|
822
|
+
const types = Array.isArray(this._lighting.type) ? this._lighting.type : [this._lighting.type];
|
|
823
|
+
lightParts.push(`${types.join(" and ")} lighting`);
|
|
824
|
+
}
|
|
825
|
+
if (this._lighting.time) lightParts.push(this._lighting.time);
|
|
826
|
+
if (this._lighting.weather) lightParts.push(`${this._lighting.weather} weather`);
|
|
827
|
+
if (this._lighting.intensity) lightParts.push(`${this._lighting.intensity} light`);
|
|
828
|
+
if (this._lighting.sources?.length) lightParts.push(`light sources: ${this._lighting.sources.join(", ")}`);
|
|
829
|
+
if (lightParts.length) sections.push(`Lighting: ${lightParts.join(", ")}`);
|
|
830
|
+
}
|
|
831
|
+
if (this._actions.length) {
|
|
832
|
+
const actionText = this._actions.map((a) => `- ${a.action}`).join("\n");
|
|
833
|
+
sections.push(`Actions:
|
|
834
|
+
${actionText}`);
|
|
835
|
+
}
|
|
836
|
+
if (this._motion?.beats?.length) {
|
|
837
|
+
sections.push(`Motion beats: ${this._motion.beats.join(", ")}`);
|
|
838
|
+
}
|
|
839
|
+
if (this._style) {
|
|
840
|
+
const styleParts = [];
|
|
841
|
+
if (this._style.format) styleParts.push(this._style.format);
|
|
842
|
+
if (this._style.era) styleParts.push(this._style.era);
|
|
843
|
+
if (this._style.filmStock) styleParts.push(`shot on ${this._style.filmStock}`);
|
|
844
|
+
if (this._style.look) {
|
|
845
|
+
const looks = Array.isArray(this._style.look) ? this._style.look : [this._style.look];
|
|
846
|
+
styleParts.push(looks.join(", "));
|
|
847
|
+
}
|
|
848
|
+
if (styleParts.length) sections.push(`Style: ${styleParts.join(", ")}`);
|
|
849
|
+
}
|
|
850
|
+
if (this._color) {
|
|
851
|
+
const colorParts = [];
|
|
852
|
+
if (this._color.palette) {
|
|
853
|
+
const palettes = Array.isArray(this._color.palette) ? this._color.palette : [this._color.palette];
|
|
854
|
+
colorParts.push(`${palettes.join(" and ")} palette`);
|
|
855
|
+
}
|
|
856
|
+
if (this._color.anchors?.length) colorParts.push(`color anchors: ${this._color.anchors.join(", ")}`);
|
|
857
|
+
if (this._color.grade) colorParts.push(this._color.grade);
|
|
858
|
+
if (colorParts.length) sections.push(`Color: ${colorParts.join(", ")}`);
|
|
859
|
+
}
|
|
860
|
+
if (this._audio) {
|
|
861
|
+
const audioParts = [];
|
|
862
|
+
if (this._audio.dialogue) audioParts.push(`Dialogue: "${this._audio.dialogue}"`);
|
|
863
|
+
if (this._audio.ambient) audioParts.push(`Ambient: ${this._audio.ambient}`);
|
|
864
|
+
if (this._audio.diegetic?.length) audioParts.push(`Diegetic sounds: ${this._audio.diegetic.join(", ")}`);
|
|
865
|
+
if (this._audio.music) audioParts.push(`Music: ${this._audio.music}`);
|
|
866
|
+
if (audioParts.length) sections.push(`Audio:
|
|
867
|
+
${audioParts.join("\n")}`);
|
|
868
|
+
}
|
|
869
|
+
if (this._mood) {
|
|
870
|
+
const moods = Array.isArray(this._mood) ? this._mood : [this._mood];
|
|
871
|
+
sections.push(`Mood: ${moods.join(", ")}`);
|
|
872
|
+
}
|
|
873
|
+
if (this._pacing) {
|
|
874
|
+
sections.push(`Pacing: ${this._pacing}`);
|
|
875
|
+
}
|
|
876
|
+
if (this._custom.length) {
|
|
877
|
+
sections.push(this._custom.join("\n"));
|
|
878
|
+
}
|
|
879
|
+
return sections.join("\n\n");
|
|
880
|
+
}
|
|
881
|
+
build() {
|
|
882
|
+
return {
|
|
883
|
+
prompt: this.buildPromptText(),
|
|
884
|
+
structure: {
|
|
885
|
+
scene: this._scene,
|
|
886
|
+
subject: this._subject,
|
|
887
|
+
camera: this._camera,
|
|
888
|
+
lighting: this._lighting,
|
|
889
|
+
actions: this._actions.length ? this._actions : void 0,
|
|
890
|
+
motion: this._motion,
|
|
891
|
+
style: this._style,
|
|
892
|
+
color: this._color,
|
|
893
|
+
audio: this._audio,
|
|
894
|
+
technical: this._technical,
|
|
895
|
+
shots: this._shots.length ? this._shots : void 0,
|
|
896
|
+
mood: this._mood,
|
|
897
|
+
pacing: this._pacing,
|
|
898
|
+
transitions: this._transitions.length ? this._transitions : void 0
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
toString() {
|
|
903
|
+
return this.build().prompt;
|
|
904
|
+
}
|
|
905
|
+
toJSON() {
|
|
906
|
+
return JSON.stringify(this.build().structure, null, 2);
|
|
907
|
+
}
|
|
908
|
+
toYAML() {
|
|
909
|
+
return objectToYaml2(this.build().structure);
|
|
910
|
+
}
|
|
911
|
+
toMarkdown() {
|
|
912
|
+
const built = this.build();
|
|
913
|
+
const sections = ["# Video Prompt\n"];
|
|
914
|
+
sections.push("## Prompt\n```\n" + built.prompt + "\n```\n");
|
|
915
|
+
if (built.structure.scene) {
|
|
916
|
+
sections.push("## Scene\n" + objectToMarkdownList2(built.structure.scene));
|
|
917
|
+
}
|
|
918
|
+
if (built.structure.subject) {
|
|
919
|
+
sections.push("## Subject\n" + objectToMarkdownList2(built.structure.subject));
|
|
920
|
+
}
|
|
921
|
+
if (built.structure.camera) {
|
|
922
|
+
sections.push("## Camera\n" + objectToMarkdownList2(built.structure.camera));
|
|
923
|
+
}
|
|
924
|
+
if (built.structure.lighting) {
|
|
925
|
+
sections.push("## Lighting\n" + objectToMarkdownList2(built.structure.lighting));
|
|
926
|
+
}
|
|
927
|
+
if (built.structure.actions) {
|
|
928
|
+
sections.push("## Actions\n" + built.structure.actions.map((a) => `- **Beat ${a.beat}:** ${a.action}`).join("\n"));
|
|
929
|
+
}
|
|
930
|
+
if (built.structure.style) {
|
|
931
|
+
sections.push("## Style\n" + objectToMarkdownList2(built.structure.style));
|
|
932
|
+
}
|
|
933
|
+
if (built.structure.audio) {
|
|
934
|
+
sections.push("## Audio\n" + objectToMarkdownList2(built.structure.audio));
|
|
935
|
+
}
|
|
936
|
+
if (built.structure.technical) {
|
|
937
|
+
sections.push("## Technical\n" + objectToMarkdownList2(built.structure.technical));
|
|
938
|
+
}
|
|
939
|
+
return sections.join("\n");
|
|
940
|
+
}
|
|
941
|
+
outputFormat(fmt) {
|
|
942
|
+
switch (fmt) {
|
|
943
|
+
case "json":
|
|
944
|
+
return this.toJSON();
|
|
945
|
+
case "yaml":
|
|
946
|
+
return this.toYAML();
|
|
947
|
+
case "markdown":
|
|
948
|
+
return this.toMarkdown();
|
|
949
|
+
default:
|
|
950
|
+
return this.toString();
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
function objectToYaml2(obj, indent = 0) {
|
|
955
|
+
const spaces = " ".repeat(indent);
|
|
956
|
+
const lines = [];
|
|
957
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
958
|
+
if (value === void 0 || value === null) continue;
|
|
959
|
+
if (Array.isArray(value)) {
|
|
960
|
+
if (value.length === 0) continue;
|
|
961
|
+
lines.push(`${spaces}${key}:`);
|
|
962
|
+
for (const item of value) {
|
|
963
|
+
if (typeof item === "object") {
|
|
964
|
+
lines.push(`${spaces} -`);
|
|
965
|
+
lines.push(objectToYaml2(item, indent + 2).replace(/^/gm, " "));
|
|
966
|
+
} else {
|
|
967
|
+
lines.push(`${spaces} - ${item}`);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
} else if (typeof value === "object") {
|
|
971
|
+
lines.push(`${spaces}${key}:`);
|
|
972
|
+
lines.push(objectToYaml2(value, indent + 1));
|
|
973
|
+
} else {
|
|
974
|
+
lines.push(`${spaces}${key}: ${value}`);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
return lines.join("\n");
|
|
978
|
+
}
|
|
979
|
+
function objectToMarkdownList2(obj, indent = 0) {
|
|
980
|
+
const spaces = " ".repeat(indent);
|
|
981
|
+
const lines = [];
|
|
982
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
983
|
+
if (value === void 0 || value === null) continue;
|
|
984
|
+
if (Array.isArray(value)) {
|
|
985
|
+
lines.push(`${spaces}- **${key}:** ${value.join(", ")}`);
|
|
986
|
+
} else if (typeof value === "object") {
|
|
987
|
+
lines.push(`${spaces}- **${key}:**`);
|
|
988
|
+
lines.push(objectToMarkdownList2(value, indent + 1));
|
|
989
|
+
} else {
|
|
990
|
+
lines.push(`${spaces}- **${key}:** ${value}`);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return lines.join("\n");
|
|
994
|
+
}
|
|
995
|
+
function video() {
|
|
996
|
+
return new VideoPromptBuilder();
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// src/builder/audio.ts
|
|
1000
|
+
var AudioPromptBuilder = class {
|
|
1001
|
+
constructor() {
|
|
1002
|
+
this._tags = [];
|
|
1003
|
+
this._custom = [];
|
|
1004
|
+
}
|
|
1005
|
+
// --- Genre Methods ---
|
|
1006
|
+
genre(primary) {
|
|
1007
|
+
if (typeof primary === "string") {
|
|
1008
|
+
this._genre = { ...this._genre || { primary: "pop" }, primary };
|
|
1009
|
+
} else {
|
|
1010
|
+
this._genre = { ...this._genre || { primary: "pop" }, ...primary };
|
|
1011
|
+
}
|
|
1012
|
+
return this;
|
|
1013
|
+
}
|
|
1014
|
+
subgenre(subgenre) {
|
|
1015
|
+
this._genre = { ...this._genre || { primary: "pop" }, subgenre };
|
|
1016
|
+
return this;
|
|
1017
|
+
}
|
|
1018
|
+
fusion(genres) {
|
|
1019
|
+
this._genre = {
|
|
1020
|
+
...this._genre || { primary: "pop" },
|
|
1021
|
+
secondary: genres,
|
|
1022
|
+
fusion: genres
|
|
1023
|
+
};
|
|
1024
|
+
return this;
|
|
1025
|
+
}
|
|
1026
|
+
// --- Mood Methods ---
|
|
1027
|
+
mood(primary, ...secondary) {
|
|
1028
|
+
this._mood = {
|
|
1029
|
+
primary,
|
|
1030
|
+
secondary: secondary.length ? secondary : void 0
|
|
1031
|
+
};
|
|
1032
|
+
return this;
|
|
1033
|
+
}
|
|
1034
|
+
energy(level) {
|
|
1035
|
+
this._mood = { ...this._mood || { primary: "energetic" }, energy: level };
|
|
1036
|
+
return this;
|
|
1037
|
+
}
|
|
1038
|
+
emotion(emotion) {
|
|
1039
|
+
this._mood = { ...this._mood || { primary: "emotional" }, emotion };
|
|
1040
|
+
return this;
|
|
1041
|
+
}
|
|
1042
|
+
// --- Tempo Methods ---
|
|
1043
|
+
tempo(bpmOrSettings) {
|
|
1044
|
+
if (typeof bpmOrSettings === "number") {
|
|
1045
|
+
this._tempo = { ...this._tempo || {}, bpm: bpmOrSettings };
|
|
1046
|
+
} else {
|
|
1047
|
+
this._tempo = { ...this._tempo || {}, ...bpmOrSettings };
|
|
1048
|
+
}
|
|
1049
|
+
return this;
|
|
1050
|
+
}
|
|
1051
|
+
bpm(bpm) {
|
|
1052
|
+
this._tempo = { ...this._tempo || {}, bpm };
|
|
1053
|
+
return this;
|
|
1054
|
+
}
|
|
1055
|
+
tempoMarking(marking) {
|
|
1056
|
+
this._tempo = { ...this._tempo || {}, marking };
|
|
1057
|
+
return this;
|
|
1058
|
+
}
|
|
1059
|
+
tempoFeel(feel) {
|
|
1060
|
+
this._tempo = { ...this._tempo || {}, feel };
|
|
1061
|
+
return this;
|
|
1062
|
+
}
|
|
1063
|
+
// --- Vocal Methods ---
|
|
1064
|
+
vocals(settings) {
|
|
1065
|
+
this._vocals = { ...this._vocals || {}, ...settings };
|
|
1066
|
+
return this;
|
|
1067
|
+
}
|
|
1068
|
+
vocalStyle(style) {
|
|
1069
|
+
this._vocals = { ...this._vocals || {}, style };
|
|
1070
|
+
return this;
|
|
1071
|
+
}
|
|
1072
|
+
language(language) {
|
|
1073
|
+
this._vocals = { ...this._vocals || {}, language };
|
|
1074
|
+
return this;
|
|
1075
|
+
}
|
|
1076
|
+
lyrics(lyrics) {
|
|
1077
|
+
this._vocals = { ...this._vocals || {}, lyrics };
|
|
1078
|
+
return this;
|
|
1079
|
+
}
|
|
1080
|
+
lyricsTheme(theme) {
|
|
1081
|
+
this._vocals = { ...this._vocals || {}, theme };
|
|
1082
|
+
return this;
|
|
1083
|
+
}
|
|
1084
|
+
delivery(delivery) {
|
|
1085
|
+
this._vocals = { ...this._vocals || {}, delivery };
|
|
1086
|
+
return this;
|
|
1087
|
+
}
|
|
1088
|
+
instrumental() {
|
|
1089
|
+
this._vocals = { ...this._vocals || {}, language: "instrumental" };
|
|
1090
|
+
return this;
|
|
1091
|
+
}
|
|
1092
|
+
// --- Instrumentation Methods ---
|
|
1093
|
+
instruments(instruments) {
|
|
1094
|
+
this._instrumentation = {
|
|
1095
|
+
...this._instrumentation || {},
|
|
1096
|
+
lead: instruments
|
|
1097
|
+
};
|
|
1098
|
+
return this;
|
|
1099
|
+
}
|
|
1100
|
+
instrumentation(settings) {
|
|
1101
|
+
this._instrumentation = { ...this._instrumentation || {}, ...settings };
|
|
1102
|
+
return this;
|
|
1103
|
+
}
|
|
1104
|
+
leadInstrument(instrument) {
|
|
1105
|
+
this._instrumentation = { ...this._instrumentation || {}, lead: instrument };
|
|
1106
|
+
return this;
|
|
1107
|
+
}
|
|
1108
|
+
rhythmSection(instruments) {
|
|
1109
|
+
this._instrumentation = { ...this._instrumentation || {}, rhythm: instruments };
|
|
1110
|
+
return this;
|
|
1111
|
+
}
|
|
1112
|
+
bassInstrument(instrument) {
|
|
1113
|
+
this._instrumentation = { ...this._instrumentation || {}, bass: instrument };
|
|
1114
|
+
return this;
|
|
1115
|
+
}
|
|
1116
|
+
percussion(instruments) {
|
|
1117
|
+
this._instrumentation = { ...this._instrumentation || {}, percussion: instruments };
|
|
1118
|
+
return this;
|
|
1119
|
+
}
|
|
1120
|
+
pads(instruments) {
|
|
1121
|
+
this._instrumentation = { ...this._instrumentation || {}, pads: instruments };
|
|
1122
|
+
return this;
|
|
1123
|
+
}
|
|
1124
|
+
featuredInstrument(instrument) {
|
|
1125
|
+
this._instrumentation = { ...this._instrumentation || {}, featured: instrument };
|
|
1126
|
+
return this;
|
|
1127
|
+
}
|
|
1128
|
+
// --- Structure Methods ---
|
|
1129
|
+
structure(settings) {
|
|
1130
|
+
if ("sections" in settings || "form" in settings || "duration" in settings) {
|
|
1131
|
+
this._structure = { ...this._structure || {}, ...settings };
|
|
1132
|
+
} else {
|
|
1133
|
+
const sections = [];
|
|
1134
|
+
for (const [type, bars] of Object.entries(settings)) {
|
|
1135
|
+
if (typeof bars === "number") {
|
|
1136
|
+
sections.push({ type, bars });
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
this._structure = { ...this._structure || {}, sections };
|
|
1140
|
+
}
|
|
1141
|
+
return this;
|
|
1142
|
+
}
|
|
1143
|
+
section(type, bars, description) {
|
|
1144
|
+
const sections = this._structure?.sections || [];
|
|
1145
|
+
sections.push({ type, bars, description });
|
|
1146
|
+
this._structure = { ...this._structure || {}, sections };
|
|
1147
|
+
return this;
|
|
1148
|
+
}
|
|
1149
|
+
form(form) {
|
|
1150
|
+
this._structure = { ...this._structure || {}, form };
|
|
1151
|
+
return this;
|
|
1152
|
+
}
|
|
1153
|
+
duration(seconds) {
|
|
1154
|
+
this._structure = { ...this._structure || {}, duration: seconds };
|
|
1155
|
+
return this;
|
|
1156
|
+
}
|
|
1157
|
+
// --- Production Methods ---
|
|
1158
|
+
production(settings) {
|
|
1159
|
+
this._production = { ...this._production || {}, ...settings };
|
|
1160
|
+
return this;
|
|
1161
|
+
}
|
|
1162
|
+
productionStyle(style) {
|
|
1163
|
+
this._production = { ...this._production || {}, style };
|
|
1164
|
+
return this;
|
|
1165
|
+
}
|
|
1166
|
+
era(era) {
|
|
1167
|
+
this._production = { ...this._production || {}, era };
|
|
1168
|
+
return this;
|
|
1169
|
+
}
|
|
1170
|
+
reference(artists) {
|
|
1171
|
+
this._production = { ...this._production || {}, reference: artists };
|
|
1172
|
+
return this;
|
|
1173
|
+
}
|
|
1174
|
+
texture(texture) {
|
|
1175
|
+
this._production = { ...this._production || {}, texture };
|
|
1176
|
+
return this;
|
|
1177
|
+
}
|
|
1178
|
+
effects(effects) {
|
|
1179
|
+
this._production = { ...this._production || {}, effects };
|
|
1180
|
+
return this;
|
|
1181
|
+
}
|
|
1182
|
+
// --- Technical Methods ---
|
|
1183
|
+
technical(settings) {
|
|
1184
|
+
this._technical = { ...this._technical || {}, ...settings };
|
|
1185
|
+
return this;
|
|
1186
|
+
}
|
|
1187
|
+
key(key) {
|
|
1188
|
+
this._technical = { ...this._technical || {}, key };
|
|
1189
|
+
return this;
|
|
1190
|
+
}
|
|
1191
|
+
timeSignature(sig) {
|
|
1192
|
+
this._technical = { ...this._technical || {}, timeSignature: sig };
|
|
1193
|
+
return this;
|
|
1194
|
+
}
|
|
1195
|
+
formatType(format) {
|
|
1196
|
+
this._technical = { ...this._technical || {}, format };
|
|
1197
|
+
return this;
|
|
1198
|
+
}
|
|
1199
|
+
// --- Tags & Custom ---
|
|
1200
|
+
tag(tag) {
|
|
1201
|
+
this._tags.push(tag);
|
|
1202
|
+
return this;
|
|
1203
|
+
}
|
|
1204
|
+
tags(tags) {
|
|
1205
|
+
this._tags = [...this._tags, ...tags];
|
|
1206
|
+
return this;
|
|
1207
|
+
}
|
|
1208
|
+
custom(text) {
|
|
1209
|
+
this._custom.push(text);
|
|
1210
|
+
return this;
|
|
1211
|
+
}
|
|
1212
|
+
// --- Build Methods ---
|
|
1213
|
+
buildStylePrompt() {
|
|
1214
|
+
const parts = [];
|
|
1215
|
+
if (this._genre) {
|
|
1216
|
+
let genreText = this._genre.primary;
|
|
1217
|
+
if (this._genre.subgenre) genreText = `${this._genre.subgenre} ${genreText}`;
|
|
1218
|
+
if (this._genre.secondary?.length) {
|
|
1219
|
+
genreText += ` with ${this._genre.secondary.join(" and ")} influences`;
|
|
1220
|
+
}
|
|
1221
|
+
parts.push(genreText);
|
|
1222
|
+
}
|
|
1223
|
+
if (this._mood) {
|
|
1224
|
+
let moodText = String(this._mood.primary);
|
|
1225
|
+
if (this._mood.secondary?.length) {
|
|
1226
|
+
moodText += `, ${this._mood.secondary.join(", ")}`;
|
|
1227
|
+
}
|
|
1228
|
+
if (this._mood.energy) moodText += `, ${this._mood.energy} energy`;
|
|
1229
|
+
parts.push(moodText);
|
|
1230
|
+
}
|
|
1231
|
+
if (this._tempo) {
|
|
1232
|
+
const tempoParts = [];
|
|
1233
|
+
if (this._tempo.bpm) tempoParts.push(`${this._tempo.bpm} BPM`);
|
|
1234
|
+
if (this._tempo.marking) tempoParts.push(this._tempo.marking);
|
|
1235
|
+
if (this._tempo.feel) tempoParts.push(`${this._tempo.feel} feel`);
|
|
1236
|
+
if (tempoParts.length) parts.push(tempoParts.join(", "));
|
|
1237
|
+
}
|
|
1238
|
+
if (this._instrumentation) {
|
|
1239
|
+
const instrParts = [];
|
|
1240
|
+
if (this._instrumentation.lead) {
|
|
1241
|
+
const leads = Array.isArray(this._instrumentation.lead) ? this._instrumentation.lead : [this._instrumentation.lead];
|
|
1242
|
+
instrParts.push(leads.join(", "));
|
|
1243
|
+
}
|
|
1244
|
+
if (this._instrumentation.featured) {
|
|
1245
|
+
instrParts.push(`featuring ${this._instrumentation.featured}`);
|
|
1246
|
+
}
|
|
1247
|
+
if (instrParts.length) parts.push(instrParts.join(", "));
|
|
1248
|
+
}
|
|
1249
|
+
if (this._vocals) {
|
|
1250
|
+
const vocalParts = [];
|
|
1251
|
+
if (this._vocals.language === "instrumental") {
|
|
1252
|
+
vocalParts.push("instrumental");
|
|
1253
|
+
} else {
|
|
1254
|
+
if (this._vocals.style) {
|
|
1255
|
+
const styles = Array.isArray(this._vocals.style) ? this._vocals.style : [this._vocals.style];
|
|
1256
|
+
vocalParts.push(`${styles.join(" and ")} vocals`);
|
|
1257
|
+
}
|
|
1258
|
+
if (this._vocals.language && this._vocals.language !== "english") {
|
|
1259
|
+
vocalParts.push(`in ${this._vocals.language}`);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
if (vocalParts.length) parts.push(vocalParts.join(" "));
|
|
1263
|
+
}
|
|
1264
|
+
if (this._production) {
|
|
1265
|
+
const prodParts = [];
|
|
1266
|
+
if (this._production.style) {
|
|
1267
|
+
const styles = Array.isArray(this._production.style) ? this._production.style : [this._production.style];
|
|
1268
|
+
prodParts.push(`${styles.join(", ")} production`);
|
|
1269
|
+
}
|
|
1270
|
+
if (this._production.era) prodParts.push(`${this._production.era} sound`);
|
|
1271
|
+
if (this._production.texture) prodParts.push(this._production.texture);
|
|
1272
|
+
if (prodParts.length) parts.push(prodParts.join(", "));
|
|
1273
|
+
}
|
|
1274
|
+
if (this._technical) {
|
|
1275
|
+
const techParts = [];
|
|
1276
|
+
if (this._technical.key) techParts.push(`in the key of ${this._technical.key}`);
|
|
1277
|
+
if (this._technical.timeSignature && this._technical.timeSignature !== "4/4") {
|
|
1278
|
+
techParts.push(`${this._technical.timeSignature} time`);
|
|
1279
|
+
}
|
|
1280
|
+
if (techParts.length) parts.push(techParts.join(", "));
|
|
1281
|
+
}
|
|
1282
|
+
if (this._tags.length) {
|
|
1283
|
+
parts.push(this._tags.join(", "));
|
|
1284
|
+
}
|
|
1285
|
+
if (this._custom.length) {
|
|
1286
|
+
parts.push(this._custom.join(", "));
|
|
1287
|
+
}
|
|
1288
|
+
return parts.join(", ");
|
|
1289
|
+
}
|
|
1290
|
+
buildLyricsPrompt() {
|
|
1291
|
+
if (!this._vocals?.lyrics && !this._vocals?.theme) return void 0;
|
|
1292
|
+
const parts = [];
|
|
1293
|
+
if (this._vocals.theme) {
|
|
1294
|
+
parts.push(`Theme: ${this._vocals.theme}`);
|
|
1295
|
+
}
|
|
1296
|
+
if (this._vocals.lyrics) {
|
|
1297
|
+
parts.push(this._vocals.lyrics);
|
|
1298
|
+
}
|
|
1299
|
+
return parts.join("\n\n");
|
|
1300
|
+
}
|
|
1301
|
+
buildFullPrompt() {
|
|
1302
|
+
const sections = [];
|
|
1303
|
+
sections.push(`Style: ${this.buildStylePrompt()}`);
|
|
1304
|
+
if (this._structure?.sections?.length) {
|
|
1305
|
+
const structureText = this._structure.sections.map((s) => `[${s.type.toUpperCase()}]${s.description ? ` ${s.description}` : ""}`).join("\n");
|
|
1306
|
+
sections.push(`Structure:
|
|
1307
|
+
${structureText}`);
|
|
1308
|
+
}
|
|
1309
|
+
const lyrics = this.buildLyricsPrompt();
|
|
1310
|
+
if (lyrics) {
|
|
1311
|
+
sections.push(`Lyrics:
|
|
1312
|
+
${lyrics}`);
|
|
1313
|
+
}
|
|
1314
|
+
return sections.join("\n\n");
|
|
1315
|
+
}
|
|
1316
|
+
build() {
|
|
1317
|
+
return {
|
|
1318
|
+
prompt: this.buildFullPrompt(),
|
|
1319
|
+
stylePrompt: this.buildStylePrompt(),
|
|
1320
|
+
lyricsPrompt: this.buildLyricsPrompt(),
|
|
1321
|
+
structure: {
|
|
1322
|
+
genre: this._genre,
|
|
1323
|
+
mood: this._mood,
|
|
1324
|
+
tempo: this._tempo,
|
|
1325
|
+
vocals: this._vocals,
|
|
1326
|
+
instrumentation: this._instrumentation,
|
|
1327
|
+
structure: this._structure,
|
|
1328
|
+
production: this._production,
|
|
1329
|
+
technical: this._technical,
|
|
1330
|
+
tags: this._tags.length ? this._tags : void 0
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
toString() {
|
|
1335
|
+
return this.build().prompt;
|
|
1336
|
+
}
|
|
1337
|
+
toStyleString() {
|
|
1338
|
+
return this.build().stylePrompt;
|
|
1339
|
+
}
|
|
1340
|
+
toJSON() {
|
|
1341
|
+
return JSON.stringify(this.build().structure, null, 2);
|
|
1342
|
+
}
|
|
1343
|
+
toYAML() {
|
|
1344
|
+
return objectToYaml3(this.build().structure);
|
|
1345
|
+
}
|
|
1346
|
+
toMarkdown() {
|
|
1347
|
+
const built = this.build();
|
|
1348
|
+
const sections = ["# Audio Prompt\n"];
|
|
1349
|
+
sections.push("## Style Prompt\n```\n" + built.stylePrompt + "\n```\n");
|
|
1350
|
+
if (built.lyricsPrompt) {
|
|
1351
|
+
sections.push("## Lyrics\n```\n" + built.lyricsPrompt + "\n```\n");
|
|
1352
|
+
}
|
|
1353
|
+
if (built.structure.genre) {
|
|
1354
|
+
sections.push("## Genre\n" + objectToMarkdownList3(built.structure.genre));
|
|
1355
|
+
}
|
|
1356
|
+
if (built.structure.mood) {
|
|
1357
|
+
sections.push("## Mood\n" + objectToMarkdownList3(built.structure.mood));
|
|
1358
|
+
}
|
|
1359
|
+
if (built.structure.tempo) {
|
|
1360
|
+
sections.push("## Tempo\n" + objectToMarkdownList3(built.structure.tempo));
|
|
1361
|
+
}
|
|
1362
|
+
if (built.structure.vocals) {
|
|
1363
|
+
sections.push("## Vocals\n" + objectToMarkdownList3(built.structure.vocals));
|
|
1364
|
+
}
|
|
1365
|
+
if (built.structure.instrumentation) {
|
|
1366
|
+
sections.push("## Instrumentation\n" + objectToMarkdownList3(built.structure.instrumentation));
|
|
1367
|
+
}
|
|
1368
|
+
if (built.structure.production) {
|
|
1369
|
+
sections.push("## Production\n" + objectToMarkdownList3(built.structure.production));
|
|
1370
|
+
}
|
|
1371
|
+
return sections.join("\n");
|
|
1372
|
+
}
|
|
1373
|
+
outputFormat(fmt) {
|
|
1374
|
+
switch (fmt) {
|
|
1375
|
+
case "json":
|
|
1376
|
+
return this.toJSON();
|
|
1377
|
+
case "yaml":
|
|
1378
|
+
return this.toYAML();
|
|
1379
|
+
case "markdown":
|
|
1380
|
+
return this.toMarkdown();
|
|
1381
|
+
default:
|
|
1382
|
+
return this.toString();
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
function objectToYaml3(obj, indent = 0) {
|
|
1387
|
+
const spaces = " ".repeat(indent);
|
|
1388
|
+
const lines = [];
|
|
1389
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1390
|
+
if (value === void 0 || value === null) continue;
|
|
1391
|
+
if (Array.isArray(value)) {
|
|
1392
|
+
if (value.length === 0) continue;
|
|
1393
|
+
lines.push(`${spaces}${key}:`);
|
|
1394
|
+
for (const item of value) {
|
|
1395
|
+
if (typeof item === "object") {
|
|
1396
|
+
lines.push(`${spaces} -`);
|
|
1397
|
+
lines.push(objectToYaml3(item, indent + 2).replace(/^/gm, " "));
|
|
1398
|
+
} else {
|
|
1399
|
+
lines.push(`${spaces} - ${item}`);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
} else if (typeof value === "object") {
|
|
1403
|
+
lines.push(`${spaces}${key}:`);
|
|
1404
|
+
lines.push(objectToYaml3(value, indent + 1));
|
|
1405
|
+
} else {
|
|
1406
|
+
lines.push(`${spaces}${key}: ${value}`);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return lines.join("\n");
|
|
1410
|
+
}
|
|
1411
|
+
function objectToMarkdownList3(obj, indent = 0) {
|
|
1412
|
+
const spaces = " ".repeat(indent);
|
|
1413
|
+
const lines = [];
|
|
1414
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1415
|
+
if (value === void 0 || value === null) continue;
|
|
1416
|
+
if (Array.isArray(value)) {
|
|
1417
|
+
lines.push(`${spaces}- **${key}:** ${value.join(", ")}`);
|
|
1418
|
+
} else if (typeof value === "object") {
|
|
1419
|
+
lines.push(`${spaces}- **${key}:**`);
|
|
1420
|
+
lines.push(objectToMarkdownList3(value, indent + 1));
|
|
1421
|
+
} else {
|
|
1422
|
+
lines.push(`${spaces}- **${key}:** ${value}`);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
return lines.join("\n");
|
|
1426
|
+
}
|
|
1427
|
+
function audio() {
|
|
1428
|
+
return new AudioPromptBuilder();
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
// src/builder/chat.ts
|
|
1432
|
+
var ChatPromptBuilder = class {
|
|
1433
|
+
constructor() {
|
|
1434
|
+
this._messages = [];
|
|
1435
|
+
this._examples = [];
|
|
1436
|
+
this._customSystemParts = [];
|
|
1437
|
+
}
|
|
1438
|
+
// --- Message Methods ---
|
|
1439
|
+
system(content) {
|
|
1440
|
+
this._messages = this._messages.filter((m) => m.role !== "system");
|
|
1441
|
+
this._messages.unshift({ role: "system", content });
|
|
1442
|
+
return this;
|
|
1443
|
+
}
|
|
1444
|
+
user(content, name) {
|
|
1445
|
+
this._messages.push({ role: "user", content, name });
|
|
1446
|
+
return this;
|
|
1447
|
+
}
|
|
1448
|
+
assistant(content) {
|
|
1449
|
+
this._messages.push({ role: "assistant", content });
|
|
1450
|
+
return this;
|
|
1451
|
+
}
|
|
1452
|
+
message(role, content, name) {
|
|
1453
|
+
this._messages.push({ role, content, name });
|
|
1454
|
+
return this;
|
|
1455
|
+
}
|
|
1456
|
+
messages(messages) {
|
|
1457
|
+
this._messages = [...this._messages, ...messages];
|
|
1458
|
+
return this;
|
|
1459
|
+
}
|
|
1460
|
+
conversation(turns) {
|
|
1461
|
+
for (const turn of turns) {
|
|
1462
|
+
this.user(turn.user);
|
|
1463
|
+
if (turn.assistant) {
|
|
1464
|
+
this.assistant(turn.assistant);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return this;
|
|
1468
|
+
}
|
|
1469
|
+
// --- Persona Methods ---
|
|
1470
|
+
persona(settings) {
|
|
1471
|
+
if (typeof settings === "string") {
|
|
1472
|
+
this._persona = { ...this._persona || {}, role: settings };
|
|
1473
|
+
} else {
|
|
1474
|
+
this._persona = { ...this._persona || {}, ...settings };
|
|
1475
|
+
}
|
|
1476
|
+
return this;
|
|
1477
|
+
}
|
|
1478
|
+
role(role) {
|
|
1479
|
+
this._persona = { ...this._persona || {}, role };
|
|
1480
|
+
return this;
|
|
1481
|
+
}
|
|
1482
|
+
tone(tone) {
|
|
1483
|
+
this._persona = { ...this._persona || {}, tone };
|
|
1484
|
+
return this;
|
|
1485
|
+
}
|
|
1486
|
+
expertise(expertise) {
|
|
1487
|
+
this._persona = { ...this._persona || {}, expertise };
|
|
1488
|
+
return this;
|
|
1489
|
+
}
|
|
1490
|
+
personality(traits) {
|
|
1491
|
+
this._persona = { ...this._persona || {}, personality: traits };
|
|
1492
|
+
return this;
|
|
1493
|
+
}
|
|
1494
|
+
background(background) {
|
|
1495
|
+
this._persona = { ...this._persona || {}, background };
|
|
1496
|
+
return this;
|
|
1497
|
+
}
|
|
1498
|
+
speakAs(name) {
|
|
1499
|
+
this._persona = { ...this._persona || {}, name };
|
|
1500
|
+
return this;
|
|
1501
|
+
}
|
|
1502
|
+
responseLanguage(language) {
|
|
1503
|
+
this._persona = { ...this._persona || {}, language };
|
|
1504
|
+
return this;
|
|
1505
|
+
}
|
|
1506
|
+
// --- Context Methods ---
|
|
1507
|
+
context(settings) {
|
|
1508
|
+
if (typeof settings === "string") {
|
|
1509
|
+
this._context = { ...this._context || {}, background: settings };
|
|
1510
|
+
} else {
|
|
1511
|
+
this._context = { ...this._context || {}, ...settings };
|
|
1512
|
+
}
|
|
1513
|
+
return this;
|
|
1514
|
+
}
|
|
1515
|
+
domain(domain) {
|
|
1516
|
+
this._context = { ...this._context || {}, domain };
|
|
1517
|
+
return this;
|
|
1518
|
+
}
|
|
1519
|
+
audience(audience) {
|
|
1520
|
+
this._context = { ...this._context || {}, audience };
|
|
1521
|
+
return this;
|
|
1522
|
+
}
|
|
1523
|
+
purpose(purpose) {
|
|
1524
|
+
this._context = { ...this._context || {}, purpose };
|
|
1525
|
+
return this;
|
|
1526
|
+
}
|
|
1527
|
+
constraints(constraints) {
|
|
1528
|
+
const existing = this._context?.constraints || [];
|
|
1529
|
+
this._context = { ...this._context || {}, constraints: [...existing, ...constraints] };
|
|
1530
|
+
return this;
|
|
1531
|
+
}
|
|
1532
|
+
constraint(constraint) {
|
|
1533
|
+
return this.constraints([constraint]);
|
|
1534
|
+
}
|
|
1535
|
+
assumptions(assumptions) {
|
|
1536
|
+
this._context = { ...this._context || {}, assumptions };
|
|
1537
|
+
return this;
|
|
1538
|
+
}
|
|
1539
|
+
knowledge(facts) {
|
|
1540
|
+
this._context = { ...this._context || {}, knowledge: facts };
|
|
1541
|
+
return this;
|
|
1542
|
+
}
|
|
1543
|
+
// --- Task Methods ---
|
|
1544
|
+
task(instruction) {
|
|
1545
|
+
if (typeof instruction === "string") {
|
|
1546
|
+
this._task = { ...this._task || { instruction: "" }, instruction };
|
|
1547
|
+
} else {
|
|
1548
|
+
this._task = { ...this._task || { instruction: "" }, ...instruction };
|
|
1549
|
+
}
|
|
1550
|
+
return this;
|
|
1551
|
+
}
|
|
1552
|
+
instruction(instruction) {
|
|
1553
|
+
this._task = { ...this._task || { instruction: "" }, instruction };
|
|
1554
|
+
return this;
|
|
1555
|
+
}
|
|
1556
|
+
steps(steps) {
|
|
1557
|
+
this._task = { ...this._task || { instruction: "" }, steps };
|
|
1558
|
+
return this;
|
|
1559
|
+
}
|
|
1560
|
+
deliverables(deliverables) {
|
|
1561
|
+
this._task = { ...this._task || { instruction: "" }, deliverables };
|
|
1562
|
+
return this;
|
|
1563
|
+
}
|
|
1564
|
+
criteria(criteria) {
|
|
1565
|
+
this._task = { ...this._task || { instruction: "" }, criteria };
|
|
1566
|
+
return this;
|
|
1567
|
+
}
|
|
1568
|
+
avoid(antiPatterns) {
|
|
1569
|
+
this._task = { ...this._task || { instruction: "" }, antiPatterns };
|
|
1570
|
+
return this;
|
|
1571
|
+
}
|
|
1572
|
+
priority(priority) {
|
|
1573
|
+
this._task = { ...this._task || { instruction: "" }, priority };
|
|
1574
|
+
return this;
|
|
1575
|
+
}
|
|
1576
|
+
// --- Example Methods ---
|
|
1577
|
+
example(input, output, explanation) {
|
|
1578
|
+
this._examples.push({ input, output, explanation });
|
|
1579
|
+
return this;
|
|
1580
|
+
}
|
|
1581
|
+
examples(examples) {
|
|
1582
|
+
this._examples = [...this._examples, ...examples];
|
|
1583
|
+
return this;
|
|
1584
|
+
}
|
|
1585
|
+
fewShot(examples) {
|
|
1586
|
+
for (const ex of examples) {
|
|
1587
|
+
this._examples.push(ex);
|
|
1588
|
+
}
|
|
1589
|
+
return this;
|
|
1590
|
+
}
|
|
1591
|
+
// --- Output Methods ---
|
|
1592
|
+
output(settings) {
|
|
1593
|
+
this._output = { ...this._output || {}, ...settings };
|
|
1594
|
+
return this;
|
|
1595
|
+
}
|
|
1596
|
+
outputFormat(format) {
|
|
1597
|
+
this._output = {
|
|
1598
|
+
...this._output || {},
|
|
1599
|
+
format: { type: format }
|
|
1600
|
+
};
|
|
1601
|
+
return this;
|
|
1602
|
+
}
|
|
1603
|
+
json(schema) {
|
|
1604
|
+
if (schema) {
|
|
1605
|
+
this._output = {
|
|
1606
|
+
...this._output || {},
|
|
1607
|
+
format: { type: "json", jsonSchema: schema }
|
|
1608
|
+
};
|
|
1609
|
+
} else {
|
|
1610
|
+
this._output = {
|
|
1611
|
+
...this._output || {},
|
|
1612
|
+
format: { type: "json" }
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
return this;
|
|
1616
|
+
}
|
|
1617
|
+
jsonSchema(name, schema, description) {
|
|
1618
|
+
this._output = {
|
|
1619
|
+
...this._output || {},
|
|
1620
|
+
format: {
|
|
1621
|
+
type: "json",
|
|
1622
|
+
jsonSchema: { name, schema, description }
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
return this;
|
|
1626
|
+
}
|
|
1627
|
+
markdown() {
|
|
1628
|
+
this._output = { ...this._output || {}, format: { type: "markdown" } };
|
|
1629
|
+
return this;
|
|
1630
|
+
}
|
|
1631
|
+
code(language) {
|
|
1632
|
+
this._output = { ...this._output || {}, format: { type: "code", language } };
|
|
1633
|
+
return this;
|
|
1634
|
+
}
|
|
1635
|
+
table() {
|
|
1636
|
+
this._output = { ...this._output || {}, format: { type: "table" } };
|
|
1637
|
+
return this;
|
|
1638
|
+
}
|
|
1639
|
+
length(length) {
|
|
1640
|
+
this._output = { ...this._output || {}, length };
|
|
1641
|
+
return this;
|
|
1642
|
+
}
|
|
1643
|
+
style(style) {
|
|
1644
|
+
this._output = { ...this._output || {}, style };
|
|
1645
|
+
return this;
|
|
1646
|
+
}
|
|
1647
|
+
brief() {
|
|
1648
|
+
return this.length("brief");
|
|
1649
|
+
}
|
|
1650
|
+
moderate() {
|
|
1651
|
+
return this.length("moderate");
|
|
1652
|
+
}
|
|
1653
|
+
detailed() {
|
|
1654
|
+
return this.length("detailed");
|
|
1655
|
+
}
|
|
1656
|
+
comprehensive() {
|
|
1657
|
+
return this.length("comprehensive");
|
|
1658
|
+
}
|
|
1659
|
+
exhaustive() {
|
|
1660
|
+
return this.length("exhaustive");
|
|
1661
|
+
}
|
|
1662
|
+
withExamples() {
|
|
1663
|
+
this._output = { ...this._output || {}, includeExamples: true };
|
|
1664
|
+
return this;
|
|
1665
|
+
}
|
|
1666
|
+
withExplanation() {
|
|
1667
|
+
this._output = { ...this._output || {}, includeExplanation: true };
|
|
1668
|
+
return this;
|
|
1669
|
+
}
|
|
1670
|
+
withSources() {
|
|
1671
|
+
this._output = { ...this._output || {}, includeSources: true };
|
|
1672
|
+
return this;
|
|
1673
|
+
}
|
|
1674
|
+
withConfidence() {
|
|
1675
|
+
this._output = { ...this._output || {}, includeConfidence: true };
|
|
1676
|
+
return this;
|
|
1677
|
+
}
|
|
1678
|
+
// --- Reasoning Methods ---
|
|
1679
|
+
reasoning(settings) {
|
|
1680
|
+
this._reasoning = { ...this._reasoning || {}, ...settings };
|
|
1681
|
+
return this;
|
|
1682
|
+
}
|
|
1683
|
+
reasoningStyle(style) {
|
|
1684
|
+
this._reasoning = { ...this._reasoning || {}, style };
|
|
1685
|
+
return this;
|
|
1686
|
+
}
|
|
1687
|
+
stepByStep() {
|
|
1688
|
+
this._reasoning = { ...this._reasoning || {}, style: "step-by-step", showWork: true };
|
|
1689
|
+
return this;
|
|
1690
|
+
}
|
|
1691
|
+
chainOfThought() {
|
|
1692
|
+
this._reasoning = { ...this._reasoning || {}, style: "chain-of-thought", showWork: true };
|
|
1693
|
+
return this;
|
|
1694
|
+
}
|
|
1695
|
+
treeOfThought() {
|
|
1696
|
+
this._reasoning = { ...this._reasoning || {}, style: "tree-of-thought", showWork: true };
|
|
1697
|
+
return this;
|
|
1698
|
+
}
|
|
1699
|
+
firstPrinciples() {
|
|
1700
|
+
this._reasoning = { ...this._reasoning || {}, style: "first-principles", showWork: true };
|
|
1701
|
+
return this;
|
|
1702
|
+
}
|
|
1703
|
+
devilsAdvocate() {
|
|
1704
|
+
this._reasoning = { ...this._reasoning || {}, style: "devil-advocate", considerAlternatives: true };
|
|
1705
|
+
return this;
|
|
1706
|
+
}
|
|
1707
|
+
showWork(show = true) {
|
|
1708
|
+
this._reasoning = { ...this._reasoning || {}, showWork: show };
|
|
1709
|
+
return this;
|
|
1710
|
+
}
|
|
1711
|
+
verifyAnswer(verify = true) {
|
|
1712
|
+
this._reasoning = { ...this._reasoning || {}, verifyAnswer: verify };
|
|
1713
|
+
return this;
|
|
1714
|
+
}
|
|
1715
|
+
considerAlternatives(consider = true) {
|
|
1716
|
+
this._reasoning = { ...this._reasoning || {}, considerAlternatives: consider };
|
|
1717
|
+
return this;
|
|
1718
|
+
}
|
|
1719
|
+
explainAssumptions(explain = true) {
|
|
1720
|
+
this._reasoning = { ...this._reasoning || {}, explainAssumptions: explain };
|
|
1721
|
+
return this;
|
|
1722
|
+
}
|
|
1723
|
+
// --- Memory Methods ---
|
|
1724
|
+
memory(memory) {
|
|
1725
|
+
this._memory = { ...this._memory || {}, ...memory };
|
|
1726
|
+
return this;
|
|
1727
|
+
}
|
|
1728
|
+
remember(facts) {
|
|
1729
|
+
const existing = this._memory?.facts || [];
|
|
1730
|
+
this._memory = { ...this._memory || {}, facts: [...existing, ...facts] };
|
|
1731
|
+
return this;
|
|
1732
|
+
}
|
|
1733
|
+
preferences(prefs) {
|
|
1734
|
+
this._memory = { ...this._memory || {}, preferences: prefs };
|
|
1735
|
+
return this;
|
|
1736
|
+
}
|
|
1737
|
+
history(messages) {
|
|
1738
|
+
this._memory = { ...this._memory || {}, history: messages };
|
|
1739
|
+
return this;
|
|
1740
|
+
}
|
|
1741
|
+
summarizeHistory(summary) {
|
|
1742
|
+
this._memory = { ...this._memory || {}, summary };
|
|
1743
|
+
return this;
|
|
1744
|
+
}
|
|
1745
|
+
// --- Custom System Prompt Parts ---
|
|
1746
|
+
addSystemPart(part) {
|
|
1747
|
+
this._customSystemParts.push(part);
|
|
1748
|
+
return this;
|
|
1749
|
+
}
|
|
1750
|
+
raw(content) {
|
|
1751
|
+
this._customSystemParts = [content];
|
|
1752
|
+
return this;
|
|
1753
|
+
}
|
|
1754
|
+
// --- Build Methods ---
|
|
1755
|
+
buildSystemPrompt() {
|
|
1756
|
+
const parts = [];
|
|
1757
|
+
if (this._persona) {
|
|
1758
|
+
let personaText = "";
|
|
1759
|
+
if (this._persona.name) {
|
|
1760
|
+
personaText += `You are ${this._persona.name}`;
|
|
1761
|
+
if (this._persona.role) personaText += `, ${this._persona.role}`;
|
|
1762
|
+
personaText += ".";
|
|
1763
|
+
} else if (this._persona.role) {
|
|
1764
|
+
personaText += `You are ${this._persona.role}.`;
|
|
1765
|
+
}
|
|
1766
|
+
if (this._persona.tone) {
|
|
1767
|
+
const tones = Array.isArray(this._persona.tone) ? this._persona.tone : [this._persona.tone];
|
|
1768
|
+
personaText += ` Your tone is ${tones.join(" and ")}.`;
|
|
1769
|
+
}
|
|
1770
|
+
if (this._persona.expertise) {
|
|
1771
|
+
const areas = Array.isArray(this._persona.expertise) ? this._persona.expertise : [this._persona.expertise];
|
|
1772
|
+
personaText += ` You have expertise in ${areas.join(", ")}.`;
|
|
1773
|
+
}
|
|
1774
|
+
if (this._persona.personality?.length) {
|
|
1775
|
+
personaText += ` You are ${this._persona.personality.join(", ")}.`;
|
|
1776
|
+
}
|
|
1777
|
+
if (this._persona.background) {
|
|
1778
|
+
personaText += ` ${this._persona.background}`;
|
|
1779
|
+
}
|
|
1780
|
+
if (this._persona.verbosity) {
|
|
1781
|
+
personaText += ` Keep responses ${this._persona.verbosity}.`;
|
|
1782
|
+
}
|
|
1783
|
+
if (this._persona.language) {
|
|
1784
|
+
personaText += ` Respond in ${this._persona.language}.`;
|
|
1785
|
+
}
|
|
1786
|
+
if (personaText) parts.push(personaText.trim());
|
|
1787
|
+
}
|
|
1788
|
+
if (this._context) {
|
|
1789
|
+
const contextParts = [];
|
|
1790
|
+
if (this._context.background) {
|
|
1791
|
+
contextParts.push(this._context.background);
|
|
1792
|
+
}
|
|
1793
|
+
if (this._context.domain) {
|
|
1794
|
+
contextParts.push(`Domain: ${this._context.domain}`);
|
|
1795
|
+
}
|
|
1796
|
+
if (this._context.audience) {
|
|
1797
|
+
contextParts.push(`Target audience: ${this._context.audience}`);
|
|
1798
|
+
}
|
|
1799
|
+
if (this._context.purpose) {
|
|
1800
|
+
contextParts.push(`Purpose: ${this._context.purpose}`);
|
|
1801
|
+
}
|
|
1802
|
+
if (this._context.knowledge?.length) {
|
|
1803
|
+
contextParts.push(`Known facts:
|
|
1804
|
+
${this._context.knowledge.map((k) => `- ${k}`).join("\n")}`);
|
|
1805
|
+
}
|
|
1806
|
+
if (this._context.assumptions?.length) {
|
|
1807
|
+
contextParts.push(`Assumptions:
|
|
1808
|
+
${this._context.assumptions.map((a) => `- ${a}`).join("\n")}`);
|
|
1809
|
+
}
|
|
1810
|
+
if (contextParts.length) {
|
|
1811
|
+
parts.push(`## Context
|
|
1812
|
+
${contextParts.join("\n")}`);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
if (this._task) {
|
|
1816
|
+
const taskParts = [];
|
|
1817
|
+
if (this._task.instruction) {
|
|
1818
|
+
taskParts.push(this._task.instruction);
|
|
1819
|
+
}
|
|
1820
|
+
if (this._task.priority) {
|
|
1821
|
+
taskParts.push(`Priority: ${this._task.priority}`);
|
|
1822
|
+
}
|
|
1823
|
+
if (this._task.steps?.length) {
|
|
1824
|
+
taskParts.push(`
|
|
1825
|
+
Steps:
|
|
1826
|
+
${this._task.steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}`);
|
|
1827
|
+
}
|
|
1828
|
+
if (this._task.deliverables?.length) {
|
|
1829
|
+
taskParts.push(`
|
|
1830
|
+
Deliverables:
|
|
1831
|
+
${this._task.deliverables.map((d) => `- ${d}`).join("\n")}`);
|
|
1832
|
+
}
|
|
1833
|
+
if (this._task.criteria?.length) {
|
|
1834
|
+
taskParts.push(`
|
|
1835
|
+
Success criteria:
|
|
1836
|
+
${this._task.criteria.map((c) => `- ${c}`).join("\n")}`);
|
|
1837
|
+
}
|
|
1838
|
+
if (this._task.antiPatterns?.length) {
|
|
1839
|
+
taskParts.push(`
|
|
1840
|
+
Avoid:
|
|
1841
|
+
${this._task.antiPatterns.map((a) => `- ${a}`).join("\n")}`);
|
|
1842
|
+
}
|
|
1843
|
+
if (taskParts.length) {
|
|
1844
|
+
parts.push(`## Task
|
|
1845
|
+
${taskParts.join("\n")}`);
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
if (this._context?.constraints?.length) {
|
|
1849
|
+
parts.push(`## Constraints
|
|
1850
|
+
${this._context.constraints.map((c, i) => `${i + 1}. ${c}`).join("\n")}`);
|
|
1851
|
+
}
|
|
1852
|
+
if (this._examples.length) {
|
|
1853
|
+
const examplesText = this._examples.map((ex, i) => {
|
|
1854
|
+
let text = `### Example ${i + 1}
|
|
1855
|
+
**Input:** ${ex.input}
|
|
1856
|
+
**Output:** ${ex.output}`;
|
|
1857
|
+
if (ex.explanation) text += `
|
|
1858
|
+
**Explanation:** ${ex.explanation}`;
|
|
1859
|
+
return text;
|
|
1860
|
+
}).join("\n\n");
|
|
1861
|
+
parts.push(`## Examples
|
|
1862
|
+
${examplesText}`);
|
|
1863
|
+
}
|
|
1864
|
+
if (this._output) {
|
|
1865
|
+
const outputParts = [];
|
|
1866
|
+
if (this._output.format) {
|
|
1867
|
+
switch (this._output.format.type) {
|
|
1868
|
+
case "json":
|
|
1869
|
+
if (this._output.format.jsonSchema) {
|
|
1870
|
+
outputParts.push(`Respond in valid JSON matching this schema:
|
|
1871
|
+
\`\`\`json
|
|
1872
|
+
${JSON.stringify(this._output.format.jsonSchema.schema, null, 2)}
|
|
1873
|
+
\`\`\``);
|
|
1874
|
+
} else {
|
|
1875
|
+
outputParts.push("Respond in valid JSON format.");
|
|
1876
|
+
}
|
|
1877
|
+
break;
|
|
1878
|
+
case "markdown":
|
|
1879
|
+
outputParts.push("Format your response using Markdown.");
|
|
1880
|
+
break;
|
|
1881
|
+
case "code":
|
|
1882
|
+
outputParts.push(`Respond with code${this._output.format.language ? ` in ${this._output.format.language}` : ""}.`);
|
|
1883
|
+
break;
|
|
1884
|
+
case "table":
|
|
1885
|
+
outputParts.push("Format your response as a table.");
|
|
1886
|
+
break;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
if (this._output.length) {
|
|
1890
|
+
outputParts.push(`Keep your response ${this._output.length}.`);
|
|
1891
|
+
}
|
|
1892
|
+
if (this._output.style) {
|
|
1893
|
+
const styleMap = {
|
|
1894
|
+
"prose": "flowing prose",
|
|
1895
|
+
"bullet-points": "bullet points",
|
|
1896
|
+
"numbered-list": "a numbered list",
|
|
1897
|
+
"table": "a table",
|
|
1898
|
+
"code": "code",
|
|
1899
|
+
"mixed": "a mix of prose and lists",
|
|
1900
|
+
"qa": "Q&A format",
|
|
1901
|
+
"dialogue": "dialogue format"
|
|
1902
|
+
};
|
|
1903
|
+
outputParts.push(`Structure as ${styleMap[this._output.style]}.`);
|
|
1904
|
+
}
|
|
1905
|
+
if (this._output.language) {
|
|
1906
|
+
outputParts.push(`Respond in ${this._output.language}.`);
|
|
1907
|
+
}
|
|
1908
|
+
if (this._output.includeExamples) {
|
|
1909
|
+
outputParts.push("Include relevant examples.");
|
|
1910
|
+
}
|
|
1911
|
+
if (this._output.includeExplanation) {
|
|
1912
|
+
outputParts.push("Include clear explanations.");
|
|
1913
|
+
}
|
|
1914
|
+
if (this._output.includeSources) {
|
|
1915
|
+
outputParts.push("Cite your sources.");
|
|
1916
|
+
}
|
|
1917
|
+
if (this._output.includeConfidence) {
|
|
1918
|
+
outputParts.push("Include your confidence level in the answer.");
|
|
1919
|
+
}
|
|
1920
|
+
if (outputParts.length) {
|
|
1921
|
+
parts.push(`## Output Format
|
|
1922
|
+
${outputParts.join("\n")}`);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
if (this._reasoning) {
|
|
1926
|
+
const reasoningParts = [];
|
|
1927
|
+
if (this._reasoning.style) {
|
|
1928
|
+
const styleInstructions = {
|
|
1929
|
+
"step-by-step": "Think through this step by step.",
|
|
1930
|
+
"chain-of-thought": "Use chain-of-thought reasoning to work through the problem.",
|
|
1931
|
+
"tree-of-thought": "Consider multiple approaches and evaluate each before deciding.",
|
|
1932
|
+
"direct": "Provide a direct answer.",
|
|
1933
|
+
"analytical": "Analyze the problem systematically.",
|
|
1934
|
+
"comparative": "Compare different options or approaches.",
|
|
1935
|
+
"deductive": "Use deductive reasoning from general principles.",
|
|
1936
|
+
"inductive": "Use inductive reasoning from specific examples.",
|
|
1937
|
+
"first-principles": "Reason from first principles, breaking down to fundamental truths.",
|
|
1938
|
+
"analogical": "Use analogies to explain and reason about the problem.",
|
|
1939
|
+
"devil-advocate": "Consider and argue against your own conclusions."
|
|
1940
|
+
};
|
|
1941
|
+
reasoningParts.push(styleInstructions[this._reasoning.style]);
|
|
1942
|
+
}
|
|
1943
|
+
if (this._reasoning.showWork) {
|
|
1944
|
+
reasoningParts.push("Show your reasoning process.");
|
|
1945
|
+
}
|
|
1946
|
+
if (this._reasoning.verifyAnswer) {
|
|
1947
|
+
reasoningParts.push("Verify your answer before presenting it.");
|
|
1948
|
+
}
|
|
1949
|
+
if (this._reasoning.considerAlternatives) {
|
|
1950
|
+
reasoningParts.push("Consider alternative perspectives and solutions.");
|
|
1951
|
+
}
|
|
1952
|
+
if (this._reasoning.explainAssumptions) {
|
|
1953
|
+
reasoningParts.push("Explicitly state any assumptions you make.");
|
|
1954
|
+
}
|
|
1955
|
+
if (reasoningParts.length) {
|
|
1956
|
+
parts.push(`## Reasoning
|
|
1957
|
+
${reasoningParts.join("\n")}`);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
if (this._memory) {
|
|
1961
|
+
const memoryParts = [];
|
|
1962
|
+
if (this._memory.summary) {
|
|
1963
|
+
memoryParts.push(`Previous conversation summary: ${this._memory.summary}`);
|
|
1964
|
+
}
|
|
1965
|
+
if (this._memory.facts?.length) {
|
|
1966
|
+
memoryParts.push(`Known facts:
|
|
1967
|
+
${this._memory.facts.map((f) => `- ${f}`).join("\n")}`);
|
|
1968
|
+
}
|
|
1969
|
+
if (this._memory.preferences?.length) {
|
|
1970
|
+
memoryParts.push(`User preferences:
|
|
1971
|
+
${this._memory.preferences.map((p) => `- ${p}`).join("\n")}`);
|
|
1972
|
+
}
|
|
1973
|
+
if (memoryParts.length) {
|
|
1974
|
+
parts.push(`## Memory
|
|
1975
|
+
${memoryParts.join("\n")}`);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
if (this._customSystemParts.length) {
|
|
1979
|
+
parts.push(...this._customSystemParts);
|
|
1980
|
+
}
|
|
1981
|
+
return parts.join("\n\n");
|
|
1982
|
+
}
|
|
1983
|
+
build() {
|
|
1984
|
+
const systemPrompt = this.buildSystemPrompt();
|
|
1985
|
+
let messages = [...this._messages];
|
|
1986
|
+
const hasSystemMessage = messages.some((m) => m.role === "system");
|
|
1987
|
+
if (systemPrompt && !hasSystemMessage) {
|
|
1988
|
+
messages = [{ role: "system", content: systemPrompt }, ...messages];
|
|
1989
|
+
} else if (systemPrompt && hasSystemMessage) {
|
|
1990
|
+
messages = messages.map(
|
|
1991
|
+
(m) => m.role === "system" ? { ...m, content: `${systemPrompt}
|
|
1992
|
+
|
|
1993
|
+
${m.content}` } : m
|
|
1994
|
+
);
|
|
1995
|
+
}
|
|
1996
|
+
if (this._memory?.history) {
|
|
1997
|
+
const systemIdx = messages.findIndex((m) => m.role === "system");
|
|
1998
|
+
const insertIdx = systemIdx >= 0 ? systemIdx + 1 : 0;
|
|
1999
|
+
messages.splice(insertIdx, 0, ...this._memory.history);
|
|
2000
|
+
}
|
|
2001
|
+
const userMessages = messages.filter((m) => m.role === "user");
|
|
2002
|
+
const userPrompt = userMessages.length ? userMessages[userMessages.length - 1].content : void 0;
|
|
2003
|
+
return {
|
|
2004
|
+
messages,
|
|
2005
|
+
systemPrompt,
|
|
2006
|
+
userPrompt,
|
|
2007
|
+
metadata: {
|
|
2008
|
+
persona: this._persona,
|
|
2009
|
+
context: this._context,
|
|
2010
|
+
task: this._task,
|
|
2011
|
+
output: this._output,
|
|
2012
|
+
reasoning: this._reasoning,
|
|
2013
|
+
examples: this._examples.length ? this._examples : void 0
|
|
2014
|
+
}
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
// --- Output Methods ---
|
|
2018
|
+
toString() {
|
|
2019
|
+
return this.buildSystemPrompt();
|
|
2020
|
+
}
|
|
2021
|
+
toSystemPrompt() {
|
|
2022
|
+
return this.buildSystemPrompt();
|
|
2023
|
+
}
|
|
2024
|
+
toMessages() {
|
|
2025
|
+
return this.build().messages;
|
|
2026
|
+
}
|
|
2027
|
+
toJSON() {
|
|
2028
|
+
return JSON.stringify(this.build(), null, 2);
|
|
2029
|
+
}
|
|
2030
|
+
toYAML() {
|
|
2031
|
+
return objectToYaml4(this.build());
|
|
2032
|
+
}
|
|
2033
|
+
toMarkdown() {
|
|
2034
|
+
const built = this.build();
|
|
2035
|
+
const sections = ["# Chat Prompt\n"];
|
|
2036
|
+
sections.push("## System Prompt\n```\n" + built.systemPrompt + "\n```\n");
|
|
2037
|
+
if (built.messages.length > 1) {
|
|
2038
|
+
sections.push("## Messages\n");
|
|
2039
|
+
for (const msg of built.messages) {
|
|
2040
|
+
if (msg.role === "system") continue;
|
|
2041
|
+
sections.push(`**${msg.role.toUpperCase()}${msg.name ? ` (${msg.name})` : ""}:**
|
|
2042
|
+
${msg.content}
|
|
2043
|
+
`);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
return sections.join("\n");
|
|
2047
|
+
}
|
|
2048
|
+
};
|
|
2049
|
+
function objectToYaml4(obj, indent = 0) {
|
|
2050
|
+
const spaces = " ".repeat(indent);
|
|
2051
|
+
const lines = [];
|
|
2052
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2053
|
+
if (value === void 0 || value === null) continue;
|
|
2054
|
+
if (Array.isArray(value)) {
|
|
2055
|
+
if (value.length === 0) continue;
|
|
2056
|
+
lines.push(`${spaces}${key}:`);
|
|
2057
|
+
for (const item of value) {
|
|
2058
|
+
if (typeof item === "object") {
|
|
2059
|
+
lines.push(`${spaces} -`);
|
|
2060
|
+
lines.push(objectToYaml4(item, indent + 2).replace(/^/gm, " "));
|
|
2061
|
+
} else {
|
|
2062
|
+
lines.push(`${spaces} - ${item}`);
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
} else if (typeof value === "object") {
|
|
2066
|
+
lines.push(`${spaces}${key}:`);
|
|
2067
|
+
lines.push(objectToYaml4(value, indent + 1));
|
|
2068
|
+
} else if (typeof value === "string" && value.includes("\n")) {
|
|
2069
|
+
lines.push(`${spaces}${key}: |`);
|
|
2070
|
+
for (const line of value.split("\n")) {
|
|
2071
|
+
lines.push(`${spaces} ${line}`);
|
|
2072
|
+
}
|
|
2073
|
+
} else {
|
|
2074
|
+
lines.push(`${spaces}${key}: ${value}`);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
return lines.join("\n");
|
|
2078
|
+
}
|
|
2079
|
+
function chat() {
|
|
2080
|
+
return new ChatPromptBuilder();
|
|
2081
|
+
}
|
|
2082
|
+
var chatPresets = {
|
|
2083
|
+
/**
|
|
2084
|
+
* Code assistant preset
|
|
2085
|
+
*/
|
|
2086
|
+
coder: (language) => {
|
|
2087
|
+
const c = chat().role("expert software developer").expertise("coding").tone("technical");
|
|
2088
|
+
if (language) {
|
|
2089
|
+
c.context(`Programming language: ${language}`);
|
|
2090
|
+
}
|
|
2091
|
+
return c;
|
|
2092
|
+
},
|
|
2093
|
+
/**
|
|
2094
|
+
* Writing assistant preset
|
|
2095
|
+
*/
|
|
2096
|
+
writer: (style) => {
|
|
2097
|
+
const c = chat().role("skilled writer and editor").expertise("writing");
|
|
2098
|
+
if (style) {
|
|
2099
|
+
c.tone(style === "creative" ? "creative" : style === "academic" ? "academic" : "professional");
|
|
2100
|
+
}
|
|
2101
|
+
return c;
|
|
2102
|
+
},
|
|
2103
|
+
/**
|
|
2104
|
+
* Teacher/tutor preset
|
|
2105
|
+
*/
|
|
2106
|
+
tutor: (subject) => {
|
|
2107
|
+
const c = chat().role("patient and knowledgeable tutor").expertise("teaching").tone(["friendly", "empathetic"]).stepByStep().withExamples();
|
|
2108
|
+
if (subject) {
|
|
2109
|
+
c.domain(subject);
|
|
2110
|
+
}
|
|
2111
|
+
return c;
|
|
2112
|
+
},
|
|
2113
|
+
/**
|
|
2114
|
+
* Analyst preset
|
|
2115
|
+
*/
|
|
2116
|
+
analyst: () => {
|
|
2117
|
+
return chat().role("data analyst and researcher").expertise("analysis").tone("analytical").chainOfThought().detailed().withSources();
|
|
2118
|
+
},
|
|
2119
|
+
/**
|
|
2120
|
+
* Socratic dialogue preset
|
|
2121
|
+
*/
|
|
2122
|
+
socratic: () => {
|
|
2123
|
+
return chat().role("Socratic philosopher and teacher").tone("socratic").reasoning({ style: "deductive", showWork: true }).avoid(["Give direct answers", "Lecture", "Be condescending"]);
|
|
2124
|
+
},
|
|
2125
|
+
/**
|
|
2126
|
+
* Critic preset
|
|
2127
|
+
*/
|
|
2128
|
+
critic: () => {
|
|
2129
|
+
return chat().role("constructive critic").tone(["analytical", "professional"]).devilsAdvocate().detailed().avoid(["Be harsh", "Dismiss ideas without explanation"]);
|
|
2130
|
+
},
|
|
2131
|
+
/**
|
|
2132
|
+
* Brainstormer preset
|
|
2133
|
+
*/
|
|
2134
|
+
brainstormer: () => {
|
|
2135
|
+
return chat().role("creative brainstorming partner").tone(["creative", "encouraging"]).expertise("creative").considerAlternatives().avoid(["Dismiss ideas", "Be negative", "Limit creativity"]);
|
|
2136
|
+
},
|
|
2137
|
+
/**
|
|
2138
|
+
* JSON response preset
|
|
2139
|
+
*/
|
|
2140
|
+
jsonResponder: (schemaName, schema) => {
|
|
2141
|
+
return chat().role("data processing assistant").tone("concise").jsonSchema(schemaName, schema).avoid(["Include markdown", "Add explanations outside JSON", "Include code fences"]);
|
|
2142
|
+
},
|
|
2143
|
+
/**
|
|
2144
|
+
* Summarizer preset
|
|
2145
|
+
*/
|
|
2146
|
+
summarizer: (length = "brief") => {
|
|
2147
|
+
return chat().role("expert summarizer").expertise("analysis").tone("concise").length(length).task("Summarize the provided content, preserving key information");
|
|
2148
|
+
},
|
|
2149
|
+
/**
|
|
2150
|
+
* Translator preset
|
|
2151
|
+
*/
|
|
2152
|
+
translator: (targetLanguage) => {
|
|
2153
|
+
return chat().role("professional translator").expertise("languages").responseLanguage(targetLanguage).avoid(["Add commentary", "Change meaning", "Omit content"]);
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
|
|
2157
|
+
// src/builder/index.ts
|
|
2158
|
+
var PromptBuilder = class {
|
|
2159
|
+
constructor() {
|
|
2160
|
+
this._constraints = [];
|
|
2161
|
+
this._examples = [];
|
|
2162
|
+
this._variables = [];
|
|
2163
|
+
this._customSections = [];
|
|
2164
|
+
}
|
|
2165
|
+
/**
|
|
2166
|
+
* Set the role/persona for the AI
|
|
2167
|
+
*/
|
|
2168
|
+
role(role) {
|
|
2169
|
+
this._role = role;
|
|
2170
|
+
return this;
|
|
2171
|
+
}
|
|
2172
|
+
/**
|
|
2173
|
+
* Alias for role()
|
|
2174
|
+
*/
|
|
2175
|
+
persona(persona) {
|
|
2176
|
+
return this.role(persona);
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* Set the context/background information
|
|
2180
|
+
*/
|
|
2181
|
+
context(context) {
|
|
2182
|
+
this._context = context;
|
|
2183
|
+
return this;
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* Alias for context()
|
|
2187
|
+
*/
|
|
2188
|
+
background(background) {
|
|
2189
|
+
return this.context(background);
|
|
2190
|
+
}
|
|
2191
|
+
/**
|
|
2192
|
+
* Set the main task/instruction
|
|
2193
|
+
*/
|
|
2194
|
+
task(task) {
|
|
2195
|
+
this._task = task;
|
|
2196
|
+
return this;
|
|
2197
|
+
}
|
|
2198
|
+
/**
|
|
2199
|
+
* Alias for task()
|
|
2200
|
+
*/
|
|
2201
|
+
instruction(instruction) {
|
|
2202
|
+
return this.task(instruction);
|
|
2203
|
+
}
|
|
2204
|
+
/**
|
|
2205
|
+
* Add constraints/rules the AI should follow
|
|
2206
|
+
*/
|
|
2207
|
+
constraints(constraints) {
|
|
2208
|
+
this._constraints = [...this._constraints, ...constraints];
|
|
2209
|
+
return this;
|
|
2210
|
+
}
|
|
2211
|
+
/**
|
|
2212
|
+
* Add a single constraint
|
|
2213
|
+
*/
|
|
2214
|
+
constraint(constraint) {
|
|
2215
|
+
this._constraints.push(constraint);
|
|
2216
|
+
return this;
|
|
2217
|
+
}
|
|
2218
|
+
/**
|
|
2219
|
+
* Alias for constraints()
|
|
2220
|
+
*/
|
|
2221
|
+
rules(rules) {
|
|
2222
|
+
return this.constraints(rules);
|
|
2223
|
+
}
|
|
2224
|
+
/**
|
|
2225
|
+
* Set the expected output format
|
|
2226
|
+
*/
|
|
2227
|
+
output(format) {
|
|
2228
|
+
this._outputFormat = format;
|
|
2229
|
+
return this;
|
|
2230
|
+
}
|
|
2231
|
+
/**
|
|
2232
|
+
* Alias for output()
|
|
2233
|
+
*/
|
|
2234
|
+
format(format) {
|
|
2235
|
+
return this.output(format);
|
|
2236
|
+
}
|
|
2237
|
+
/**
|
|
2238
|
+
* Add an example input/output pair
|
|
2239
|
+
*/
|
|
2240
|
+
example(input, output) {
|
|
2241
|
+
this._examples.push({ input, output });
|
|
2242
|
+
return this;
|
|
2243
|
+
}
|
|
2244
|
+
/**
|
|
2245
|
+
* Add multiple examples
|
|
2246
|
+
*/
|
|
2247
|
+
examples(examples) {
|
|
2248
|
+
this._examples = [...this._examples, ...examples];
|
|
2249
|
+
return this;
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Define a variable placeholder
|
|
2253
|
+
*/
|
|
2254
|
+
variable(name, options = {}) {
|
|
2255
|
+
this._variables.push({
|
|
2256
|
+
name,
|
|
2257
|
+
description: options.description,
|
|
2258
|
+
required: options.required ?? true,
|
|
2259
|
+
defaultValue: options.defaultValue
|
|
2260
|
+
});
|
|
2261
|
+
return this;
|
|
2262
|
+
}
|
|
2263
|
+
/**
|
|
2264
|
+
* Add a custom section
|
|
2265
|
+
*/
|
|
2266
|
+
section(title, content) {
|
|
2267
|
+
this._customSections.push({ title, content });
|
|
2268
|
+
return this;
|
|
2269
|
+
}
|
|
2270
|
+
/**
|
|
2271
|
+
* Set raw content (bypasses structured building)
|
|
2272
|
+
*/
|
|
2273
|
+
raw(content) {
|
|
2274
|
+
this._rawContent = content;
|
|
2275
|
+
return this;
|
|
2276
|
+
}
|
|
2277
|
+
/**
|
|
2278
|
+
* Build the final prompt
|
|
2279
|
+
*/
|
|
2280
|
+
build() {
|
|
2281
|
+
if (this._rawContent) {
|
|
2282
|
+
return {
|
|
2283
|
+
content: this._rawContent,
|
|
2284
|
+
variables: this._variables,
|
|
2285
|
+
metadata: {}
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
const sections = [];
|
|
2289
|
+
if (this._role) {
|
|
2290
|
+
sections.push(`You are ${this._role}.`);
|
|
2291
|
+
}
|
|
2292
|
+
if (this._context) {
|
|
2293
|
+
sections.push(`
|
|
2294
|
+
## Context
|
|
2295
|
+
${this._context}`);
|
|
2296
|
+
}
|
|
2297
|
+
if (this._task) {
|
|
2298
|
+
sections.push(`
|
|
2299
|
+
## Task
|
|
2300
|
+
${this._task}`);
|
|
2301
|
+
}
|
|
2302
|
+
if (this._constraints.length > 0) {
|
|
2303
|
+
const constraintsList = this._constraints.map((c, i) => `${i + 1}. ${c}`).join("\n");
|
|
2304
|
+
sections.push(`
|
|
2305
|
+
## Constraints
|
|
2306
|
+
${constraintsList}`);
|
|
2307
|
+
}
|
|
2308
|
+
if (this._outputFormat) {
|
|
2309
|
+
sections.push(`
|
|
2310
|
+
## Output Format
|
|
2311
|
+
${this._outputFormat}`);
|
|
2312
|
+
}
|
|
2313
|
+
if (this._examples.length > 0) {
|
|
2314
|
+
const examplesText = this._examples.map((e, i) => `### Example ${i + 1}
|
|
2315
|
+
**Input:** ${e.input}
|
|
2316
|
+
**Output:** ${e.output}`).join("\n\n");
|
|
2317
|
+
sections.push(`
|
|
2318
|
+
## Examples
|
|
2319
|
+
${examplesText}`);
|
|
2320
|
+
}
|
|
2321
|
+
for (const section of this._customSections) {
|
|
2322
|
+
sections.push(`
|
|
2323
|
+
## ${section.title}
|
|
2324
|
+
${section.content}`);
|
|
2325
|
+
}
|
|
2326
|
+
if (this._variables.length > 0) {
|
|
2327
|
+
const varsText = this._variables.map((v) => {
|
|
2328
|
+
const placeholder = v.defaultValue ? `\${${v.name}:${v.defaultValue}}` : `\${${v.name}}`;
|
|
2329
|
+
const desc = v.description ? ` - ${v.description}` : "";
|
|
2330
|
+
const req = v.required ? " (required)" : " (optional)";
|
|
2331
|
+
return `- ${placeholder}${desc}${req}`;
|
|
2332
|
+
}).join("\n");
|
|
2333
|
+
sections.push(`
|
|
2334
|
+
## Variables
|
|
2335
|
+
${varsText}`);
|
|
2336
|
+
}
|
|
2337
|
+
return {
|
|
2338
|
+
content: sections.join("\n").trim(),
|
|
2339
|
+
variables: this._variables,
|
|
2340
|
+
metadata: {
|
|
2341
|
+
role: this._role,
|
|
2342
|
+
context: this._context,
|
|
2343
|
+
task: this._task,
|
|
2344
|
+
constraints: this._constraints.length > 0 ? this._constraints : void 0,
|
|
2345
|
+
outputFormat: this._outputFormat,
|
|
2346
|
+
examples: this._examples.length > 0 ? this._examples : void 0
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
}
|
|
2350
|
+
/**
|
|
2351
|
+
* Build and return only the content string
|
|
2352
|
+
*/
|
|
2353
|
+
toString() {
|
|
2354
|
+
return this.build().content;
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
function builder() {
|
|
2358
|
+
return new PromptBuilder();
|
|
2359
|
+
}
|
|
2360
|
+
function fromPrompt(content) {
|
|
2361
|
+
return new PromptBuilder().raw(content);
|
|
2362
|
+
}
|
|
2363
|
+
var templates = {
|
|
2364
|
+
/**
|
|
2365
|
+
* Create a code review prompt
|
|
2366
|
+
*/
|
|
2367
|
+
codeReview: (options = {}) => {
|
|
2368
|
+
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" });
|
|
2369
|
+
if (options.language) {
|
|
2370
|
+
b.context(`You are reviewing ${options.language} code.`);
|
|
2371
|
+
}
|
|
2372
|
+
if (options.focus && options.focus.length > 0) {
|
|
2373
|
+
b.constraints(options.focus.map((f) => `Focus on ${f}`));
|
|
2374
|
+
}
|
|
2375
|
+
return b.output("Provide a structured review with: issues found, suggestions, and overall assessment.");
|
|
2376
|
+
},
|
|
2377
|
+
/**
|
|
2378
|
+
* Create a translation prompt
|
|
2379
|
+
*/
|
|
2380
|
+
translation: (from, to) => {
|
|
2381
|
+
return builder().role(`professional translator fluent in ${from} and ${to}`).task(`Translate the following text from ${from} to ${to}.`).constraints([
|
|
2382
|
+
"Maintain the original meaning and tone",
|
|
2383
|
+
"Use natural, idiomatic expressions in the target language",
|
|
2384
|
+
"Preserve formatting and structure"
|
|
2385
|
+
]).variable("text", { required: true, description: "Text to translate" });
|
|
2386
|
+
},
|
|
2387
|
+
/**
|
|
2388
|
+
* Create a summarization prompt
|
|
2389
|
+
*/
|
|
2390
|
+
summarize: (options = {}) => {
|
|
2391
|
+
const b = builder().role("expert summarizer").task("Summarize the following content concisely while preserving key information.").variable("content", { required: true, description: "Content to summarize" });
|
|
2392
|
+
if (options.maxLength) {
|
|
2393
|
+
b.constraint(`Keep the summary under ${options.maxLength} words`);
|
|
2394
|
+
}
|
|
2395
|
+
if (options.style === "bullet") {
|
|
2396
|
+
b.output("Provide the summary as bullet points");
|
|
2397
|
+
}
|
|
2398
|
+
return b;
|
|
2399
|
+
},
|
|
2400
|
+
/**
|
|
2401
|
+
* Create a Q&A prompt
|
|
2402
|
+
*/
|
|
2403
|
+
qa: (context) => {
|
|
2404
|
+
const b = builder().role("helpful assistant").task("Answer the question based on the provided context.").variable("question", { required: true, description: "The question to answer" });
|
|
2405
|
+
if (context) {
|
|
2406
|
+
b.context(context);
|
|
2407
|
+
} else {
|
|
2408
|
+
b.variable("context", { required: false, description: "Additional context" });
|
|
2409
|
+
}
|
|
2410
|
+
return b.constraints([
|
|
2411
|
+
"Be accurate and concise",
|
|
2412
|
+
"If you don't know the answer, say so",
|
|
2413
|
+
"Cite relevant parts of the context if applicable"
|
|
2414
|
+
]);
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
export {
|
|
2418
|
+
AudioPromptBuilder,
|
|
2419
|
+
ChatPromptBuilder,
|
|
2420
|
+
ImagePromptBuilder,
|
|
2421
|
+
PromptBuilder,
|
|
2422
|
+
VideoPromptBuilder,
|
|
2423
|
+
audio,
|
|
2424
|
+
builder,
|
|
2425
|
+
chat,
|
|
2426
|
+
chatPresets,
|
|
2427
|
+
fromPrompt,
|
|
2428
|
+
image,
|
|
2429
|
+
templates,
|
|
2430
|
+
video
|
|
2431
|
+
};
|
|
2432
|
+
//# sourceMappingURL=index.mjs.map
|