@promptbook/anthropic-claude 0.102.0-9 → 0.103.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/esm/index.es.js +933 -9
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/color.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/components.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  6. package/esm/typings/src/_packages/utils.index.d.ts +2 -0
  7. package/esm/typings/src/book-components/Chat/Chat/ChatMessageItem.d.ts +9 -1
  8. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +4 -0
  9. package/esm/typings/src/book-components/Chat/save/_common/ChatSaveFormatDefinition.d.ts +43 -5
  10. package/esm/typings/src/book-components/Chat/save/html/htmlSaveFormatDefinition.d.ts +9 -2
  11. package/esm/typings/src/book-components/Chat/save/index.d.ts +38 -8
  12. package/esm/typings/src/book-components/Chat/save/json/jsonSaveFormatDefinition.d.ts +6 -2
  13. package/esm/typings/src/book-components/Chat/save/markdown/mdSaveFormatDefinition.d.ts +5 -1
  14. package/esm/typings/src/book-components/Chat/save/pdf/pdfSaveFormatDefinition.d.ts +6 -2
  15. package/esm/typings/src/book-components/Chat/save/react/reactSaveFormatDefinition.d.ts +16 -0
  16. package/esm/typings/src/book-components/Chat/save/text/txtSaveFormatDefinition.d.ts +5 -1
  17. package/esm/typings/src/book-components/Chat/types/ChatMessage.d.ts +1 -1
  18. package/esm/typings/src/book-components/Chat/types/ChatParticipant.d.ts +1 -1
  19. package/esm/typings/src/book-components/Chat/utils/exportChatHistory.d.ts +1 -1
  20. package/esm/typings/src/book-components/icons/SaveIcon.d.ts +10 -0
  21. package/esm/typings/src/config.d.ts +26 -4
  22. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +1 -1
  23. package/esm/typings/src/utils/color/Color.d.ts +8 -0
  24. package/esm/typings/src/utils/color/operators/darken.d.ts +2 -1
  25. package/esm/typings/src/utils/color/operators/grayscale.d.ts +2 -1
  26. package/esm/typings/src/utils/color/operators/lighten.d.ts +2 -1
  27. package/esm/typings/src/utils/color/operators/mixWithColor.d.ts +2 -1
  28. package/esm/typings/src/utils/color/operators/saturate.d.ts +13 -0
  29. package/esm/typings/src/utils/serialization/serializeToPromptbookJavascript.d.ts +22 -0
  30. package/esm/typings/src/version.d.ts +1 -1
  31. package/package.json +2 -2
  32. package/umd/index.umd.js +933 -9
  33. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -19,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
19
19
  * @generated
20
20
  * @see https://github.com/webgptorg/promptbook
21
21
  */
22
- const PROMPTBOOK_ENGINE_VERSION = '0.102.0-9';
22
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-0';
23
23
  /**
24
24
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
25
25
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -67,6 +67,895 @@ function $deepFreeze(objectValue) {
67
67
  * TODO: [🧠] Is there a way how to meaningfully test this utility
68
68
  */
69
69
 
70
+ /**
71
+ * @private util of `@promptbook/color`
72
+ * @de
73
+ */
74
+ class TakeChain {
75
+ constructor(value) {
76
+ this.value = value;
77
+ }
78
+ then(callback) {
79
+ const newValue = callback(this.value);
80
+ return take(newValue);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * A function that takes an initial value and returns a proxy object with chainable methods.
86
+ *
87
+ * @param {*} initialValue - The initial value.
88
+ * @returns {Proxy<WithTake<TValue>>} - A proxy object with a `take` method.
89
+ *
90
+ * @private util of `@promptbook/color`
91
+ * @deprecated [🤡] Use some better functional library instead of `TakeChain`
92
+ */
93
+ function take(initialValue) {
94
+ if (initialValue instanceof TakeChain) {
95
+ return initialValue;
96
+ }
97
+ return new Proxy(new TakeChain(initialValue), {
98
+ get(target, property, receiver) {
99
+ if (Reflect.has(target, property)) {
100
+ return Reflect.get(target, property, receiver);
101
+ }
102
+ else if (Reflect.has(initialValue, property)) {
103
+ return Reflect.get(initialValue, property, receiver);
104
+ }
105
+ else {
106
+ return undefined;
107
+ }
108
+ },
109
+ });
110
+ }
111
+
112
+ /**
113
+ * 🎨 List of all 140 color names which are supported by CSS
114
+ *
115
+ * @public exported from `@promptbook/color`
116
+ */
117
+ const CSS_COLORS = {
118
+ transparent: 'rgba(0,0,0,0)',
119
+ aliceblue: '#f0f8ff',
120
+ antiquewhite: '#faebd7',
121
+ aqua: '#00ffff',
122
+ aquamarine: '#7fffd4',
123
+ azure: '#f0ffff',
124
+ beige: '#f5f5dc',
125
+ bisque: '#ffe4c4',
126
+ black: '#000000',
127
+ blanchedalmond: '#ffebcd',
128
+ blue: '#0000ff',
129
+ blueviolet: '#8a2be2',
130
+ brown: '#a52a2a',
131
+ burlywood: '#deb887',
132
+ cadetblue: '#5f9ea0',
133
+ chartreuse: '#7fff00',
134
+ chocolate: '#d2691e',
135
+ coral: '#ff7f50',
136
+ cornflowerblue: '#6495ed',
137
+ cornsilk: '#fff8dc',
138
+ crimson: '#dc143c',
139
+ cyan: '#00ffff',
140
+ darkblue: '#00008b',
141
+ darkcyan: '#008b8b',
142
+ darkgoldenrod: '#b8860b',
143
+ darkgray: '#a9a9a9',
144
+ darkgrey: '#a9a9a9',
145
+ darkgreen: '#006400',
146
+ darkkhaki: '#bdb76b',
147
+ darkmagenta: '#8b008b',
148
+ darkolivegreen: '#556b2f',
149
+ darkorange: '#ff8c00',
150
+ darkorchid: '#9932cc',
151
+ darkred: '#8b0000',
152
+ darksalmon: '#e9967a',
153
+ darkseagreen: '#8fbc8f',
154
+ darkslateblue: '#483d8b',
155
+ darkslategray: '#2f4f4f',
156
+ darkslategrey: '#2f4f4f',
157
+ darkturquoise: '#00ced1',
158
+ darkviolet: '#9400d3',
159
+ deeppink: '#ff1493',
160
+ deepskyblue: '#00bfff',
161
+ dimgray: '#696969',
162
+ dimgrey: '#696969',
163
+ dodgerblue: '#1e90ff',
164
+ firebrick: '#b22222',
165
+ floralwhite: '#fffaf0',
166
+ forestgreen: '#228b22',
167
+ fuchsia: '#ff00ff',
168
+ gainsboro: '#dcdcdc',
169
+ ghostwhite: '#f8f8ff',
170
+ gold: '#ffd700',
171
+ goldenrod: '#daa520',
172
+ gray: '#808080',
173
+ grey: '#808080',
174
+ green: '#008000',
175
+ greenyellow: '#adff2f',
176
+ honeydew: '#f0fff0',
177
+ hotpink: '#ff69b4',
178
+ indianred: '#cd5c5c',
179
+ indigo: '#4b0082',
180
+ ivory: '#fffff0',
181
+ khaki: '#f0e68c',
182
+ lavender: '#e6e6fa',
183
+ lavenderblush: '#fff0f5',
184
+ lawngreen: '#7cfc00',
185
+ lemonchiffon: '#fffacd',
186
+ lightblue: '#add8e6',
187
+ lightcoral: '#f08080',
188
+ lightcyan: '#e0ffff',
189
+ lightgoldenrodyellow: '#fafad2',
190
+ lightgray: '#d3d3d3',
191
+ lightgrey: '#d3d3d3',
192
+ lightgreen: '#90ee90',
193
+ lightpink: '#ffb6c1',
194
+ lightsalmon: '#ffa07a',
195
+ lightseagreen: '#20b2aa',
196
+ lightskyblue: '#87cefa',
197
+ lightslategray: '#778899',
198
+ lightslategrey: '#778899',
199
+ lightsteelblue: '#b0c4de',
200
+ lightyellow: '#ffffe0',
201
+ lime: '#00ff00',
202
+ limegreen: '#32cd32',
203
+ linen: '#faf0e6',
204
+ magenta: '#ff00ff',
205
+ maroon: '#800000',
206
+ mediumaquamarine: '#66cdaa',
207
+ mediumblue: '#0000cd',
208
+ mediumorchid: '#ba55d3',
209
+ mediumpurple: '#9370db',
210
+ mediumseagreen: '#3cb371',
211
+ mediumslateblue: '#7b68ee',
212
+ mediumspringgreen: '#00fa9a',
213
+ mediumturquoise: '#48d1cc',
214
+ mediumvioletred: '#c71585',
215
+ midnightblue: '#191970',
216
+ mintcream: '#f5fffa',
217
+ mistyrose: '#ffe4e1',
218
+ moccasin: '#ffe4b5',
219
+ navajowhite: '#ffdead',
220
+ navy: '#000080',
221
+ oldlace: '#fdf5e6',
222
+ olive: '#808000',
223
+ olivedrab: '#6b8e23',
224
+ orange: '#ffa500',
225
+ orangered: '#ff4500',
226
+ orchid: '#da70d6',
227
+ palegoldenrod: '#eee8aa',
228
+ palegreen: '#98fb98',
229
+ paleturquoise: '#afeeee',
230
+ palevioletred: '#db7093',
231
+ papayawhip: '#ffefd5',
232
+ peachpuff: '#ffdab9',
233
+ peru: '#cd853f',
234
+ pink: '#ffc0cb',
235
+ plum: '#dda0dd',
236
+ powderblue: '#b0e0e6',
237
+ purple: '#800080',
238
+ rebeccapurple: '#663399',
239
+ red: '#ff0000',
240
+ rosybrown: '#bc8f8f',
241
+ royalblue: '#4169e1',
242
+ saddlebrown: '#8b4513',
243
+ salmon: '#fa8072',
244
+ sandybrown: '#f4a460',
245
+ seagreen: '#2e8b57',
246
+ seashell: '#fff5ee',
247
+ sienna: '#a0522d',
248
+ silver: '#c0c0c0',
249
+ skyblue: '#87ceeb',
250
+ slateblue: '#6a5acd',
251
+ slategray: '#708090',
252
+ slategrey: '#708090',
253
+ snow: '#fffafa',
254
+ springgreen: '#00ff7f',
255
+ steelblue: '#4682b4',
256
+ tan: '#d2b48c',
257
+ teal: '#008080',
258
+ thistle: '#d8bfd8',
259
+ tomato: '#ff6347',
260
+ turquoise: '#40e0d0',
261
+ violet: '#ee82ee',
262
+ wheat: '#f5deb3',
263
+ white: '#ffffff',
264
+ whitesmoke: '#f5f5f5',
265
+ yellow: '#ffff00',
266
+ yellowgreen: '#9acd32',
267
+ };
268
+ /**
269
+ * Note: [💞] Ignore a discrepancy between file name and entity name
270
+ */
271
+
272
+ /**
273
+ * Validates that a channel value is a valid number within the range of 0 to 255.
274
+ * Throws an error if the value is not valid.
275
+ *
276
+ * @param channelName - The name of the channel being validated.
277
+ * @param value - The value of the channel to validate.
278
+ * @throws Will throw an error if the value is not a valid channel number.
279
+ *
280
+ * @private util of `@promptbook/color`
281
+ */
282
+ function checkChannelValue(channelName, value) {
283
+ if (typeof value !== 'number') {
284
+ throw new Error(`${channelName} channel value is not number but ${typeof value}`);
285
+ }
286
+ if (isNaN(value)) {
287
+ throw new Error(`${channelName} channel value is NaN`);
288
+ }
289
+ if (Math.round(value) !== value) {
290
+ throw new Error(`${channelName} channel is not whole number, it is ${value}`);
291
+ }
292
+ if (value < 0) {
293
+ throw new Error(`${channelName} channel is lower than 0, it is ${value}`);
294
+ }
295
+ if (value > 255) {
296
+ throw new Error(`${channelName} channel is greater than 255, it is ${value}`);
297
+ }
298
+ }
299
+ /**
300
+ * TODO: [🧠][🚓] Is/which combination it better to use asserts/check, validate or is utility function?
301
+ */
302
+
303
+ /**
304
+ * Color object represents an RGB color with alpha channel
305
+ *
306
+ * Note: There is no fromObject/toObject because the most logical way to serialize color is as a hex string (#009edd)
307
+ *
308
+ * @public exported from `@promptbook/color`
309
+ */
310
+ class Color {
311
+ /**
312
+ * Creates a new Color instance from miscellaneous formats
313
+ * - It can receive Color instance and just return the same instance
314
+ * - It can receive color in string format for example `#009edd`, `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`, `hsl(197.1,100%,43.3%)`
315
+ *
316
+ * Note: This is not including fromImage because detecting color from an image is heavy task which requires async stuff and we cannot safely determine with overloading if return value will be a promise
317
+ *
318
+ * @param color
319
+ * @returns Color object
320
+ */
321
+ static from(color) {
322
+ if (color instanceof Color) {
323
+ return take(color);
324
+ }
325
+ else if (Color.isColor(color)) {
326
+ return take(color);
327
+ }
328
+ else if (typeof color === 'string') {
329
+ return Color.fromString(color);
330
+ }
331
+ else {
332
+ console.error({ color });
333
+ throw new Error(`Can not create color from given object`);
334
+ }
335
+ }
336
+ /**
337
+ * Creates a new Color instance from miscellaneous string formats
338
+ *
339
+ * @param color as a string for example `#009edd`, `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`, `hsl(197.1,100%,43.3%)`, `red`, `darkgrey`,...
340
+ * @returns Color object
341
+ */
342
+ static fromString(color) {
343
+ if (CSS_COLORS[color]) {
344
+ return Color.fromString(CSS_COLORS[color]);
345
+ // -----
346
+ }
347
+ else if (Color.isHexColorString(color)) {
348
+ return Color.fromHex(color);
349
+ // -----
350
+ }
351
+ else if (/^hsl\(\s*(\d+)\s*,\s*(\d+(?:\.\d+)?%)\s*,\s*(\d+(?:\.\d+)?%)\)$/.test(color)) {
352
+ return Color.fromHsl(color);
353
+ // -----
354
+ }
355
+ else if (/^rgb\((\s*[0-9-.%]+\s*,?){3}\)$/.test(color)) {
356
+ // TODO: [0] Should be fromRgbString and fromRgbaString one or two functions
357
+ return Color.fromRgbString(color);
358
+ // -----
359
+ }
360
+ else if (/^rgba\((\s*[0-9-.%]+\s*,?){4}\)$/.test(color)) {
361
+ return Color.fromRgbaString(color);
362
+ // -----
363
+ }
364
+ else {
365
+ throw new Error(`Can not create a new Color instance from string "${color}".`);
366
+ }
367
+ }
368
+ /**
369
+ * Gets common color
370
+ *
371
+ * @param key as a css string like `midnightblue`
372
+ * @returns Color object
373
+ */
374
+ static get(key) {
375
+ if (!CSS_COLORS[key]) {
376
+ throw new Error(`"${key}" is not a common css color.`);
377
+ }
378
+ return Color.fromString(CSS_COLORS[key]);
379
+ }
380
+ /**
381
+ * Creates a new Color instance from average color of given image
382
+ *
383
+ * @param image as a source for example `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdjYJh39z8ABJgCe/ZvAS4AAAAASUVORK5CYII=`
384
+ * @returns Color object
385
+ */
386
+ static async fromImage(image) {
387
+ return Color.fromHex(`#009edd`);
388
+ }
389
+ /**
390
+ * Creates a new Color instance from color in hex format
391
+ *
392
+ * @param color in hex for example `#009edd`, `009edd`, `#555`,...
393
+ * @returns Color object
394
+ */
395
+ static fromHex(hex) {
396
+ const hexOriginal = hex;
397
+ if (hex.startsWith('#')) {
398
+ hex = hex.substring(1);
399
+ }
400
+ if (hex.length === 3) {
401
+ return Color.fromHex3(hex);
402
+ }
403
+ if (hex.length === 6) {
404
+ return Color.fromHex6(hex);
405
+ }
406
+ if (hex.length === 8) {
407
+ return Color.fromHex8(hex);
408
+ }
409
+ throw new Error(`Can not parse color from hex string "${hexOriginal}"`);
410
+ }
411
+ /**
412
+ * Creates a new Color instance from color in hex format with 3 color digits (without alpha channel)
413
+ *
414
+ * @param color in hex for example `09d`
415
+ * @returns Color object
416
+ */
417
+ static fromHex3(hex) {
418
+ const r = parseInt(hex.substr(0, 1), 16) * 16;
419
+ const g = parseInt(hex.substr(1, 1), 16) * 16;
420
+ const b = parseInt(hex.substr(2, 1), 16) * 16;
421
+ return take(new Color(r, g, b));
422
+ }
423
+ /**
424
+ * Creates a new Color instance from color in hex format with 6 color digits (without alpha channel)
425
+ *
426
+ * @param color in hex for example `009edd`
427
+ * @returns Color object
428
+ */
429
+ static fromHex6(hex) {
430
+ const r = parseInt(hex.substr(0, 2), 16);
431
+ const g = parseInt(hex.substr(2, 2), 16);
432
+ const b = parseInt(hex.substr(4, 2), 16);
433
+ return take(new Color(r, g, b));
434
+ }
435
+ /**
436
+ * Creates a new Color instance from color in hex format with 8 color digits (with alpha channel)
437
+ *
438
+ * @param color in hex for example `009edd`
439
+ * @returns Color object
440
+ */
441
+ static fromHex8(hex) {
442
+ const r = parseInt(hex.substr(0, 2), 16);
443
+ const g = parseInt(hex.substr(2, 2), 16);
444
+ const b = parseInt(hex.substr(4, 2), 16);
445
+ const a = parseInt(hex.substr(6, 2), 16);
446
+ return take(new Color(r, g, b, a));
447
+ }
448
+ /**
449
+ * Creates a new Color instance from color in hsl format
450
+ *
451
+ * @param color as a hsl for example `hsl(197.1,100%,43.3%)`
452
+ * @returns Color object
453
+ */
454
+ static fromHsl(hsl) {
455
+ const match = hsl.match(/^hsl\(\s*([0-9.]+)\s*,\s*([0-9.]+)%\s*,\s*([0-9.]+)%\s*\)$/);
456
+ if (!match) {
457
+ throw new Error(`Invalid hsl string format: "${hsl}"`);
458
+ }
459
+ const h = parseFloat(match[1]);
460
+ const s = parseFloat(match[2]) / 100;
461
+ const l = parseFloat(match[3]) / 100;
462
+ // HSL to RGB conversion
463
+ const c = (1 - Math.abs(2 * l - 1)) * s;
464
+ const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
465
+ const m = l - c / 2;
466
+ let r1 = 0, g1 = 0, b1 = 0;
467
+ if (h >= 0 && h < 60) {
468
+ r1 = c;
469
+ g1 = x;
470
+ b1 = 0;
471
+ }
472
+ else if (h >= 60 && h < 120) {
473
+ r1 = x;
474
+ g1 = c;
475
+ b1 = 0;
476
+ }
477
+ else if (h >= 120 && h < 180) {
478
+ r1 = 0;
479
+ g1 = c;
480
+ b1 = x;
481
+ }
482
+ else if (h >= 180 && h < 240) {
483
+ r1 = 0;
484
+ g1 = x;
485
+ b1 = c;
486
+ }
487
+ else if (h >= 240 && h < 300) {
488
+ r1 = x;
489
+ g1 = 0;
490
+ b1 = c;
491
+ }
492
+ else if (h >= 300 && h < 360) {
493
+ r1 = c;
494
+ g1 = 0;
495
+ b1 = x;
496
+ }
497
+ const r = Math.round((r1 + m) * 255);
498
+ const g = Math.round((g1 + m) * 255);
499
+ const b = Math.round((b1 + m) * 255);
500
+ return take(new Color(r, g, b));
501
+ }
502
+ /**
503
+ * Creates a new Color instance from color in rgb format
504
+ *
505
+ * @param color as a rgb for example `rgb(0,158,221)`, `rgb(0%,62%,86.7%)`
506
+ * @returns Color object
507
+ */
508
+ static fromRgbString(rgb) {
509
+ const match = rgb.match(/^rgb\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/);
510
+ if (!match) {
511
+ throw new Error(`Invalid rgb string format: "${rgb}"`);
512
+ }
513
+ const parseChannel = (value) => {
514
+ if (value.endsWith('%')) {
515
+ // Percentage value
516
+ const percent = parseFloat(value);
517
+ return Math.round((percent / 100) * 255);
518
+ }
519
+ else {
520
+ // Numeric value
521
+ return Math.round(parseFloat(value));
522
+ }
523
+ };
524
+ const r = parseChannel(match[1]);
525
+ const g = parseChannel(match[2]);
526
+ const b = parseChannel(match[3]);
527
+ return take(new Color(r, g, b));
528
+ }
529
+ /**
530
+ * Creates a new Color instance from color in rbga format
531
+ *
532
+ * @param color as a rgba for example `rgba(0,158,221,0.5)`, `rgb(0%,62%,86.7%,50%)`
533
+ * @returns Color object
534
+ */
535
+ static fromRgbaString(rgba) {
536
+ const match = rgba.match(/^rgba\(\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*,\s*([0-9.%-]+)\s*\)$/);
537
+ if (!match) {
538
+ throw new Error(`Invalid rgba string format: "${rgba}"`);
539
+ }
540
+ const parseChannel = (value) => {
541
+ if (value.endsWith('%')) {
542
+ const percent = parseFloat(value);
543
+ return Math.round((percent / 100) * 255);
544
+ }
545
+ else {
546
+ return Math.round(parseFloat(value));
547
+ }
548
+ };
549
+ const parseAlpha = (value) => {
550
+ if (value.endsWith('%')) {
551
+ const percent = parseFloat(value);
552
+ return Math.round((percent / 100) * 255);
553
+ }
554
+ else {
555
+ const alphaFloat = parseFloat(value);
556
+ // If alpha is between 0 and 1, treat as float
557
+ if (alphaFloat <= 1) {
558
+ return Math.round(alphaFloat * 255);
559
+ }
560
+ // Otherwise, treat as 0-255
561
+ return Math.round(alphaFloat);
562
+ }
563
+ };
564
+ const r = parseChannel(match[1]);
565
+ const g = parseChannel(match[2]);
566
+ const b = parseChannel(match[3]);
567
+ const a = parseAlpha(match[4]);
568
+ return take(new Color(r, g, b, a));
569
+ }
570
+ /**
571
+ * Creates a new Color for color channels values
572
+ *
573
+ * @param red number from 0 to 255
574
+ * @param green number from 0 to 255
575
+ * @param blue number from 0 to 255
576
+ * @param alpha number from 0 (transparent) to 255 (opaque = default)
577
+ * @returns Color object
578
+ */
579
+ static fromValues(red, green, blue, alpha = 255) {
580
+ return take(new Color(red, green, blue, alpha));
581
+ }
582
+ /**
583
+ * Checks if the given value is a valid Color object.
584
+ *
585
+ * @param {unknown} value - The value to check.
586
+ * @return {value is WithTake<Color>} Returns true if the value is a valid Color object, false otherwise.
587
+ */
588
+ static isColor(value) {
589
+ if (typeof value !== 'object') {
590
+ return false;
591
+ }
592
+ if (value === null) {
593
+ return false;
594
+ }
595
+ if (typeof value.red !== 'number' ||
596
+ typeof value.green !== 'number' ||
597
+ typeof value.blue !== 'number' ||
598
+ typeof value.alpha !== 'number') {
599
+ return false;
600
+ }
601
+ if (typeof value.then !== 'function') {
602
+ return false;
603
+ }
604
+ return true;
605
+ }
606
+ /**
607
+ * Checks if the given value is a valid hex color string
608
+ *
609
+ * @param value - value to check
610
+ * @returns true if the value is a valid hex color string (e.g., `#009edd`, `#fff`, etc.)
611
+ */
612
+ static isHexColorString(value) {
613
+ return typeof value === 'string' && /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(value);
614
+ }
615
+ /**
616
+ * Creates new Color object
617
+ *
618
+ * Note: Consider using one of static methods like `from` or `fromString`
619
+ *
620
+ * @param red number from 0 to 255
621
+ * @param green number from 0 to 255
622
+ * @param blue number from 0 to 255
623
+ * @param alpha number from 0 (transparent) to 255 (opaque)
624
+ */
625
+ constructor(red, green, blue, alpha = 255) {
626
+ this.red = red;
627
+ this.green = green;
628
+ this.blue = blue;
629
+ this.alpha = alpha;
630
+ checkChannelValue('Red', red);
631
+ checkChannelValue('Green', green);
632
+ checkChannelValue('Blue', blue);
633
+ checkChannelValue('Alpha', alpha);
634
+ }
635
+ /**
636
+ * Shortcut for `red` property
637
+ * Number from 0 to 255
638
+ * @alias red
639
+ */
640
+ get r() {
641
+ return this.red;
642
+ }
643
+ /**
644
+ * Shortcut for `green` property
645
+ * Number from 0 to 255
646
+ * @alias green
647
+ */
648
+ get g() {
649
+ return this.green;
650
+ }
651
+ /**
652
+ * Shortcut for `blue` property
653
+ * Number from 0 to 255
654
+ * @alias blue
655
+ */
656
+ get b() {
657
+ return this.blue;
658
+ }
659
+ /**
660
+ * Shortcut for `alpha` property
661
+ * Number from 0 (transparent) to 255 (opaque)
662
+ * @alias alpha
663
+ */
664
+ get a() {
665
+ return this.alpha;
666
+ }
667
+ /**
668
+ * Shortcut for `alpha` property
669
+ * Number from 0 (transparent) to 255 (opaque)
670
+ * @alias alpha
671
+ */
672
+ get opacity() {
673
+ return this.alpha;
674
+ }
675
+ /**
676
+ * Shortcut for 1-`alpha` property
677
+ */
678
+ get transparency() {
679
+ return 255 - this.alpha;
680
+ }
681
+ clone() {
682
+ return take(new Color(this.red, this.green, this.blue, this.alpha));
683
+ }
684
+ toString() {
685
+ return this.toHex();
686
+ }
687
+ toHex() {
688
+ if (this.alpha === 255) {
689
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
690
+ .toString(16)
691
+ .padStart(2, '0')}`;
692
+ }
693
+ else {
694
+ return `#${this.red.toString(16).padStart(2, '0')}${this.green.toString(16).padStart(2, '0')}${this.blue
695
+ .toString(16)
696
+ .padStart(2, '0')}${this.alpha.toString(16).padStart(2, '0')}`;
697
+ }
698
+ }
699
+ toRgb() {
700
+ if (this.alpha === 255) {
701
+ return `rgb(${this.red}, ${this.green}, ${this.blue})`;
702
+ }
703
+ else {
704
+ return `rgba(${this.red}, ${this.green}, ${this.blue}, ${Math.round((this.alpha / 255) * 100)}%)`;
705
+ }
706
+ }
707
+ toHsl() {
708
+ throw new Error(`Getting HSL is not implemented`);
709
+ }
710
+ }
711
+ /**
712
+ * TODO: [🥻] Split Color class and color type
713
+ * TODO: For each method a corresponding static method should be created
714
+ * Like clone can be done by color.clone() OR Color.clone(color)
715
+ * TODO: Probably as an independent LIB OR add to LIB xyzt (ask @roseckyj)
716
+ * TODO: !! Transfer back to Collboard (whole directory)
717
+ * TODO: Maybe [🏌️‍♂️] change ACRY toString => (toHex) toRgb when there will be toRgb and toRgba united
718
+ * TODO: Convert getters to methods - getters only for values
719
+ * TODO: Write tests
720
+ * TODO: Getters for alpha, opacity, transparency, r, b, g, h, s, l, a,...
721
+ * TODO: [0] Should be fromRgbString and fromRgbaString one or two functions + one or two regex
722
+ * TODO: Use rgb, rgba, hsl for testing and parsing with the same regex
723
+ * TODO: Regex for rgb, rgba, hsl does not support all options like deg, rad, turn,...
724
+ * TODO: Convolution matrix
725
+ * TODO: Maybe connect with textures
726
+ */
727
+
728
+ /**
729
+ * Converts HSL values to RGB values
730
+ *
731
+ * @param hue [0-1]
732
+ * @param saturation [0-1]
733
+ * @param lightness [0-1]
734
+ * @returns [red, green, blue] [0-255]
735
+ *
736
+ * @private util of `@promptbook/color`
737
+ */
738
+ function hslToRgb(hue, saturation, lightness) {
739
+ let red;
740
+ let green;
741
+ let blue;
742
+ if (saturation === 0) {
743
+ // achromatic
744
+ red = lightness;
745
+ green = lightness;
746
+ blue = lightness;
747
+ }
748
+ else {
749
+ // TODO: Extract to separate function
750
+ const hue2rgb = (p, q, t) => {
751
+ if (t < 0)
752
+ t += 1;
753
+ if (t > 1)
754
+ t -= 1;
755
+ if (t < 1 / 6)
756
+ return p + (q - p) * 6 * t;
757
+ if (t < 1 / 2)
758
+ return q;
759
+ if (t < 2 / 3)
760
+ return p + (q - p) * (2 / 3 - t) * 6;
761
+ return p;
762
+ };
763
+ const q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
764
+ const p = 2 * lightness - q;
765
+ red = hue2rgb(p, q, hue + 1 / 3);
766
+ green = hue2rgb(p, q, hue);
767
+ blue = hue2rgb(p, q, hue - 1 / 3);
768
+ }
769
+ return [Math.round(red * 255), Math.round(green * 255), Math.round(blue * 255)];
770
+ }
771
+ /**
772
+ * TODO: Properly name all used internal variables
773
+ */
774
+
775
+ /**
776
+ * Converts RGB values to HSL values
777
+ *
778
+ * @param red [0-255]
779
+ * @param green [0-255]
780
+ * @param blue [0-255]
781
+ * @returns [hue, saturation, lightness] [0-1]
782
+ *
783
+ * @private util of `@promptbook/color`
784
+ */
785
+ function rgbToHsl(red, green, blue) {
786
+ red /= 255;
787
+ green /= 255;
788
+ blue /= 255;
789
+ const max = Math.max(red, green, blue);
790
+ const min = Math.min(red, green, blue);
791
+ let hue;
792
+ let saturation;
793
+ const lightness = (max + min) / 2;
794
+ if (max === min) {
795
+ // achromatic
796
+ hue = 0;
797
+ saturation = 0;
798
+ }
799
+ else {
800
+ const d = max - min;
801
+ saturation = lightness > 0.5 ? d / (2 - max - min) : d / (max + min);
802
+ switch (max) {
803
+ case red:
804
+ hue = (green - blue) / d + (green < blue ? 6 : 0);
805
+ break;
806
+ case green:
807
+ hue = (blue - red) / d + 2;
808
+ break;
809
+ case blue:
810
+ hue = (red - green) / d + 4;
811
+ break;
812
+ default:
813
+ hue = 0;
814
+ }
815
+ hue /= 6;
816
+ }
817
+ return [hue, saturation, lightness];
818
+ }
819
+ /**
820
+ * TODO: Properly name all used internal variables
821
+ */
822
+
823
+ /**
824
+ * Makes color transformer which lighten the given color
825
+ *
826
+ * @param amount from 0 to 1
827
+ *
828
+ * @public exported from `@promptbook/color`
829
+ */
830
+ function lighten(amount) {
831
+ return ({ red, green, blue, alpha }) => {
832
+ const [h, s, lInitial] = rgbToHsl(red, green, blue);
833
+ let l = lInitial + amount;
834
+ l = Math.max(0, Math.min(l, 1)); // Replace lodash clamp with Math.max and Math.min
835
+ const [r, g, b] = hslToRgb(h, s, l);
836
+ return Color.fromValues(r, g, b, alpha);
837
+ };
838
+ }
839
+ /**
840
+ * TODO: Maybe implement by mix+hsl
841
+ */
842
+
843
+ /**
844
+ * Calculates distance between two colors
845
+ *
846
+ * @param color1 first color
847
+ * @param color2 second color
848
+ *
849
+ * Note: This function is inefficient. Use colorDistanceSquared instead if possible.
850
+ *
851
+ * @public exported from `@promptbook/color`
852
+ */
853
+ /**
854
+ * Calculates distance between two colors without square root
855
+ *
856
+ * @param color1 first color
857
+ * @param color2 second color
858
+ *
859
+ * @public exported from `@promptbook/color`
860
+ */
861
+ function colorDistanceSquared(color1, color2) {
862
+ const rmean = (color1.red + color2.red) / 2;
863
+ const r = color1.red - color2.red;
864
+ const g = color1.green - color2.green;
865
+ const b = color1.blue - color2.blue;
866
+ const weightR = 2 + rmean / 256;
867
+ const weightG = 4.0;
868
+ const weightB = 2 + (255 - rmean) / 256;
869
+ const distance = weightR * r * r + weightG * g * g + weightB * b * b;
870
+ return distance;
871
+ }
872
+
873
+ /**
874
+ * Makes color transformer which finds the nearest color from the given list
875
+ *
876
+ * @param colors array of colors to choose from
877
+ *
878
+ * @public exported from `@promptbook/color`
879
+ */
880
+ function nearest(...colors) {
881
+ return (color) => {
882
+ const distances = colors.map((c) => colorDistanceSquared(c, color));
883
+ const minDistance = Math.min(...distances);
884
+ const minIndex = distances.indexOf(minDistance);
885
+ const nearestColor = colors[minIndex];
886
+ return nearestColor;
887
+ };
888
+ }
889
+
890
+ /**
891
+ * Color transformer which returns the negative color
892
+ *
893
+ * @public exported from `@promptbook/color`
894
+ */
895
+ function negative(color) {
896
+ const r = 255 - color.red;
897
+ const g = 255 - color.green;
898
+ const b = 255 - color.blue;
899
+ return Color.fromValues(r, g, b, color.alpha);
900
+ }
901
+
902
+ /**
903
+ * Makes color transformer which finds the furthest color from the given list
904
+ *
905
+ * @param colors array of colors to choose from
906
+ *
907
+ * @public exported from `@promptbook/color`
908
+ */
909
+ function furthest(...colors) {
910
+ return (color) => {
911
+ const furthestColor = negative(nearest(...colors.map(negative))(color));
912
+ return furthestColor;
913
+ };
914
+ }
915
+ /**
916
+ * Makes color transformer which finds the best text color (black or white) for the given background color
917
+ *
918
+ * @public exported from `@promptbook/color`
919
+ */
920
+ furthest(Color.get('white'), Color.from('black'));
921
+
922
+ /**
923
+ * Makes color transformer which returns a grayscale version of the color
924
+ *
925
+ * @param amount from 0 to 1
926
+ *
927
+ * @public exported from `@promptbook/color`
928
+ */
929
+ function grayscale(amount) {
930
+ return ({ red, green, blue, alpha }) => {
931
+ const average = (red + green + blue) / 3;
932
+ red = Math.round(average * amount + red * (1 - amount));
933
+ green = Math.round(average * amount + green * (1 - amount));
934
+ blue = Math.round(average * amount + blue * (1 - amount));
935
+ return Color.fromValues(red, green, blue, alpha);
936
+ };
937
+ }
938
+
939
+ /**
940
+ * Makes color transformer which saturate the given color
941
+ *
942
+ * @param amount from -1 to 1
943
+ *
944
+ * @public exported from `@promptbook/color`
945
+ */
946
+ function saturate(amount) {
947
+ return ({ red, green, blue, alpha }) => {
948
+ const [h, sInitial, l] = rgbToHsl(red, green, blue);
949
+ let s = sInitial + amount;
950
+ s = Math.max(0, Math.min(s, 1));
951
+ const [r, g, b] = hslToRgb(h, s, l);
952
+ return Color.fromValues(r, g, b, alpha);
953
+ };
954
+ }
955
+ /**
956
+ * TODO: Maybe implement by mix+hsl
957
+ */
958
+
70
959
  /**
71
960
  * Name for the Promptbook
72
961
  *
@@ -87,6 +976,32 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
87
976
  * @public exported from `@promptbook/core`
88
977
  */
89
978
  const ADMIN_GITHUB_NAME = 'hejny';
979
+ // <- TODO: [🐊] Pick the best claim
980
+ /**
981
+ * Color of the Promptbook
982
+ *
983
+ * TODO: [🗽] Unite branding and make single place for it
984
+ *
985
+ * @public exported from `@promptbook/core`
986
+ */
987
+ const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
988
+ // <- TODO: [🧠] Using `Color` here increases the package size approx 3kb, maybe remove it
989
+ /**
990
+ * Dark color of the Promptbook
991
+ *
992
+ * TODO: [🗽] Unite branding and make single place for it
993
+ *
994
+ * @public exported from `@promptbook/core`
995
+ */
996
+ PROMPTBOOK_COLOR.then(lighten(0.1)).then(saturate(0.9)).then(grayscale(0.9));
997
+ /**
998
+ * Color of the user (in chat)
999
+ *
1000
+ * TODO: [🗽] Unite branding and make single place for it
1001
+ *
1002
+ * @public exported from `@promptbook/core`
1003
+ */
1004
+ Color.fromHex('#1D4ED8');
90
1005
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
91
1006
  /**
92
1007
  * The maximum number of iterations for a loops
@@ -1521,19 +2436,28 @@ class AnthropicClaudeExecutionTools {
1521
2436
  }
1522
2437
  const modelName = modelRequirements.modelName || this.getDefaultChatModel().modelName;
1523
2438
  const rawPromptContent = templateParameters(content, { ...parameters, modelName });
2439
+ // Support chat thread if provided, otherwise fallback to single message
2440
+ let messages;
2441
+ if ('thread' in prompt && Array.isArray(prompt.thread)) {
2442
+ messages = prompt.thread.map((msg) => ({
2443
+ role: msg.role === 'assistant' ? 'assistant' : 'user',
2444
+ content: msg.content,
2445
+ }));
2446
+ }
2447
+ else {
2448
+ messages = [
2449
+ {
2450
+ role: 'user',
2451
+ content: rawPromptContent,
2452
+ },
2453
+ ];
2454
+ }
1524
2455
  const rawRequest = {
1525
2456
  model: modelRequirements.modelName || this.getDefaultChatModel().modelName,
1526
2457
  max_tokens: modelRequirements.maxTokens || 8192,
1527
2458
  temperature: modelRequirements.temperature,
1528
2459
  system: modelRequirements.systemMessage,
1529
- messages: [
1530
- {
1531
- role: 'user',
1532
- content: rawPromptContent,
1533
- // <- TODO: [🧠][♏] Maybe if expecting JSON and its not specified in prompt content, append the instructions
1534
- // @see https://docs.anthropic.com/en/docs/test-and-evaluate/strengthen-guardrails/increase-consistency#specify-the-desired-output-format
1535
- },
1536
- ],
2460
+ messages,
1537
2461
  };
1538
2462
  const start = $getCurrentDate();
1539
2463
  if (this.options.isVerbose) {