@promptbook/utils 0.105.0-5 → 0.105.0-7

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/umd/index.umd.js CHANGED
@@ -23,7 +23,7 @@
23
23
  * @generated
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-5';
26
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-7';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -3062,6 +3062,709 @@
3062
3062
  };
3063
3063
  }
3064
3064
 
3065
+ /**
3066
+ * Makes first letter of a string uppercase
3067
+ *
3068
+ * Note: [🔂] This function is idempotent.
3069
+ *
3070
+ * @public exported from `@promptbook/utils`
3071
+ */
3072
+ function capitalize(word) {
3073
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
3074
+ }
3075
+
3076
+ /**
3077
+ * Creates human-readable hash
3078
+ *
3079
+ * @public exported from `@promptbook/utils`
3080
+ */
3081
+ async function linguisticHash(input) {
3082
+ const hash = computeHash(input);
3083
+ // Use parts of the hash to select words
3084
+ // SHA256 is 64 hex characters
3085
+ // We use different slices of the hash to ensure variety even with small changes in input
3086
+ const part1 = parseInt(hash.substring(0, 10), 16);
3087
+ const part2 = parseInt(hash.substring(10, 20), 16);
3088
+ const part3 = parseInt(hash.substring(20, 30), 16);
3089
+ const adjective = ADJECTIVES[part1 % ADJECTIVES.length];
3090
+ const noun = NOUNS[part2 % NOUNS.length];
3091
+ const verb = VERBS[part3 % VERBS.length];
3092
+ return `${capitalize(adjective)} ${noun.toLowerCase()} ${verb.toLowerCase()}`;
3093
+ }
3094
+ const ADJECTIVES = [
3095
+ 'red',
3096
+ 'blue',
3097
+ 'green',
3098
+ 'yellow',
3099
+ 'quick',
3100
+ 'slow',
3101
+ 'bright',
3102
+ 'dark',
3103
+ 'happy',
3104
+ 'sad',
3105
+ 'brave',
3106
+ 'calm',
3107
+ 'clever',
3108
+ 'eager',
3109
+ 'fancy',
3110
+ 'grand',
3111
+ 'jolly',
3112
+ 'kind',
3113
+ 'lucky',
3114
+ 'nice',
3115
+ 'proud',
3116
+ 'silly',
3117
+ 'wise',
3118
+ 'young',
3119
+ 'old',
3120
+ 'big',
3121
+ 'small',
3122
+ 'fast',
3123
+ 'shiny',
3124
+ 'wild',
3125
+ 'silent',
3126
+ 'loud',
3127
+ 'soft',
3128
+ 'hard',
3129
+ 'warm',
3130
+ 'cold',
3131
+ 'sweet',
3132
+ 'sour',
3133
+ 'bitter',
3134
+ 'salty',
3135
+ 'rich',
3136
+ 'poor',
3137
+ 'heavy',
3138
+ 'light',
3139
+ 'strong',
3140
+ 'weak',
3141
+ 'smooth',
3142
+ 'rough',
3143
+ 'clean',
3144
+ 'dirty',
3145
+ 'fresh',
3146
+ 'stale',
3147
+ 'sharp',
3148
+ 'blunt',
3149
+ 'thick',
3150
+ 'thin',
3151
+ 'wide',
3152
+ 'narrow',
3153
+ 'deep',
3154
+ 'shallow',
3155
+ 'mighty',
3156
+ 'gentle',
3157
+ 'fierce',
3158
+ 'vibrant',
3159
+ 'dusty',
3160
+ 'golden',
3161
+ 'silver',
3162
+ 'frozen',
3163
+ 'burning',
3164
+ 'ancient',
3165
+ 'modern',
3166
+ 'hidden',
3167
+ 'lost',
3168
+ 'found',
3169
+ 'magic',
3170
+ 'mystic',
3171
+ 'cosmic',
3172
+ 'stellar',
3173
+ 'lunar',
3174
+ 'solar',
3175
+ 'misty',
3176
+ 'foggy',
3177
+ 'stormy',
3178
+ 'sunny',
3179
+ 'windy',
3180
+ 'quiet',
3181
+ 'noisy',
3182
+ 'peaceful',
3183
+ 'busy',
3184
+ 'empty',
3185
+ 'full',
3186
+ 'round',
3187
+ 'square',
3188
+ 'flat',
3189
+ 'curved',
3190
+ 'tiny',
3191
+ 'huge',
3192
+ 'giant',
3193
+ 'little',
3194
+ 'short',
3195
+ 'long',
3196
+ 'near',
3197
+ 'distant',
3198
+ 'inner',
3199
+ 'outer',
3200
+ 'patient',
3201
+ 'steady',
3202
+ 'noble',
3203
+ 'pure',
3204
+ 'graceful',
3205
+ 'honest',
3206
+ 'simple',
3207
+ 'complex',
3208
+ 'active',
3209
+ 'passive',
3210
+ 'vivid',
3211
+ 'pale',
3212
+ 'loyal',
3213
+ 'true',
3214
+ 'false',
3215
+ 'fair',
3216
+ 'clear',
3217
+ 'murky',
3218
+ 'vast',
3219
+ 'slick',
3220
+ 'slippery',
3221
+ 'sticky',
3222
+ 'dull',
3223
+ 'keen',
3224
+ 'broad',
3225
+ 'slim',
3226
+ 'slender',
3227
+ 'fat',
3228
+ 'lean',
3229
+ 'stiff',
3230
+ 'flexible',
3231
+ 'rigid',
3232
+ 'elastic',
3233
+ 'tough',
3234
+ 'brittle',
3235
+ 'fragile',
3236
+ 'solid',
3237
+ 'liquid',
3238
+ 'gaseous',
3239
+ 'airy',
3240
+ 'weighty',
3241
+ 'buoyant',
3242
+ 'dense',
3243
+ 'sparse',
3244
+ 'hollow',
3245
+ 'stuffed',
3246
+ 'crowded',
3247
+ 'lonely',
3248
+ 'social',
3249
+ 'private',
3250
+ 'public',
3251
+ 'secret',
3252
+ 'famous',
3253
+ 'certain',
3254
+ 'vague',
3255
+ 'plain',
3256
+ 'easy',
3257
+ 'tame',
3258
+ 'mild',
3259
+ 'hot',
3260
+ 'cool',
3261
+ 'dry',
3262
+ 'wet',
3263
+ 'damp',
3264
+ 'moist',
3265
+ 'soaked',
3266
+ 'parched',
3267
+ 'hungry',
3268
+ 'thirsty',
3269
+ 'sleepy',
3270
+ 'awake',
3271
+ 'tired',
3272
+ 'lazy',
3273
+ 'idle',
3274
+ 'swift',
3275
+ 'rapid',
3276
+ 'unstable',
3277
+ 'shaky',
3278
+ 'firm',
3279
+ 'bold',
3280
+ 'timid',
3281
+ 'brave',
3282
+ 'cowardly',
3283
+ 'smart',
3284
+ 'dumb',
3285
+ 'foolish',
3286
+ 'mean',
3287
+ 'rude',
3288
+ 'tasty',
3289
+ 'bland',
3290
+ 'arctic',
3291
+ 'tropical',
3292
+ 'deserted',
3293
+ 'urban',
3294
+ 'rural',
3295
+ 'local',
3296
+ 'global',
3297
+ 'digital',
3298
+ 'analog',
3299
+ 'virtual',
3300
+ 'real',
3301
+ 'fake',
3302
+ 'natural',
3303
+ 'artificial',
3304
+ 'living',
3305
+ 'dead',
3306
+ 'broken',
3307
+ 'fixed',
3308
+ 'new',
3309
+ 'worn',
3310
+ 'neat',
3311
+ 'messy',
3312
+ 'brave',
3313
+ 'fearful',
3314
+ 'proud',
3315
+ 'humble',
3316
+ 'greedy',
3317
+ 'generous',
3318
+ 'calm',
3319
+ 'angry',
3320
+ 'happy',
3321
+ 'sad',
3322
+ 'excited',
3323
+ 'bored',
3324
+ 'strange',
3325
+ 'normal',
3326
+ 'odd',
3327
+ 'even',
3328
+ 'rare',
3329
+ 'common',
3330
+ 'unique',
3331
+ 'plain',
3332
+ 'fancy',
3333
+ 'basic',
3334
+ 'prime',
3335
+ 'super',
3336
+ 'mega',
3337
+ 'ultra',
3338
+ 'micro',
3339
+ 'nano',
3340
+ 'macro',
3341
+ 'mini',
3342
+ ];
3343
+ const NOUNS = [
3344
+ 'apple',
3345
+ 'sky',
3346
+ 'tree',
3347
+ 'fox',
3348
+ 'cat',
3349
+ 'bird',
3350
+ 'dog',
3351
+ 'river',
3352
+ 'mountain',
3353
+ 'forest',
3354
+ 'ocean',
3355
+ 'star',
3356
+ 'moon',
3357
+ 'sun',
3358
+ 'cloud',
3359
+ 'flower',
3360
+ 'leaf',
3361
+ 'stone',
3362
+ 'wind',
3363
+ 'rain',
3364
+ 'fire',
3365
+ 'ice',
3366
+ 'book',
3367
+ 'dream',
3368
+ 'song',
3369
+ 'road',
3370
+ 'gate',
3371
+ 'key',
3372
+ 'lamp',
3373
+ 'map',
3374
+ 'house',
3375
+ 'city',
3376
+ 'bridge',
3377
+ 'field',
3378
+ 'garden',
3379
+ 'lake',
3380
+ 'beach',
3381
+ 'island',
3382
+ 'valley',
3383
+ 'desert',
3384
+ 'world',
3385
+ 'spirit',
3386
+ 'heart',
3387
+ 'mind',
3388
+ 'soul',
3389
+ 'life',
3390
+ 'time',
3391
+ 'space',
3392
+ 'light',
3393
+ 'shadow',
3394
+ 'sound',
3395
+ 'music',
3396
+ 'voice',
3397
+ 'word',
3398
+ 'page',
3399
+ 'story',
3400
+ 'pearl',
3401
+ 'gold',
3402
+ 'silver',
3403
+ 'crystal',
3404
+ 'diamond',
3405
+ 'emerald',
3406
+ 'ruby',
3407
+ 'path',
3408
+ 'trail',
3409
+ 'peak',
3410
+ 'shore',
3411
+ 'wave',
3412
+ 'tide',
3413
+ 'flame',
3414
+ 'spark',
3415
+ 'beam',
3416
+ 'ray',
3417
+ 'seed',
3418
+ 'root',
3419
+ 'branch',
3420
+ 'bloom',
3421
+ 'thorn',
3422
+ 'bark',
3423
+ 'shell',
3424
+ 'feather',
3425
+ 'wing',
3426
+ 'claw',
3427
+ 'paw',
3428
+ 'nest',
3429
+ 'cave',
3430
+ 'grove',
3431
+ 'tower',
3432
+ 'castle',
3433
+ 'crown',
3434
+ 'sword',
3435
+ 'shield',
3436
+ 'coin',
3437
+ 'gem',
3438
+ 'ring',
3439
+ 'bell',
3440
+ 'clock',
3441
+ 'compass',
3442
+ 'anchor',
3443
+ 'torch',
3444
+ 'flute',
3445
+ 'harp',
3446
+ 'drum',
3447
+ 'lens',
3448
+ 'glass',
3449
+ 'sand',
3450
+ 'dust',
3451
+ 'mist',
3452
+ 'dew',
3453
+ 'dawn',
3454
+ 'dusk',
3455
+ 'night',
3456
+ 'day',
3457
+ 'year',
3458
+ 'age',
3459
+ 'bolt',
3460
+ 'drop',
3461
+ 'storm',
3462
+ 'snow',
3463
+ 'hail',
3464
+ 'fog',
3465
+ 'smoke',
3466
+ 'vapor',
3467
+ 'gas',
3468
+ 'fluid',
3469
+ 'liquid',
3470
+ 'solid',
3471
+ 'metal',
3472
+ 'rock',
3473
+ 'dirt',
3474
+ 'clay',
3475
+ 'sand',
3476
+ 'salt',
3477
+ 'sugar',
3478
+ 'wood',
3479
+ 'bone',
3480
+ 'skin',
3481
+ 'flesh',
3482
+ 'blood',
3483
+ 'cell',
3484
+ 'atom',
3485
+ 'pulse',
3486
+ 'beat',
3487
+ 'breath',
3488
+ 'sigh',
3489
+ 'name',
3490
+ 'echo',
3491
+ 'image',
3492
+ 'vision',
3493
+ 'thought',
3494
+ 'idea',
3495
+ 'plan',
3496
+ 'goal',
3497
+ 'wish',
3498
+ 'hope',
3499
+ 'fear',
3500
+ 'joy',
3501
+ 'love',
3502
+ 'hate',
3503
+ 'will',
3504
+ 'power',
3505
+ 'force',
3506
+ 'energy',
3507
+ 'motion',
3508
+ 'speed',
3509
+ 'place',
3510
+ 'point',
3511
+ 'line',
3512
+ 'shape',
3513
+ 'form',
3514
+ 'size',
3515
+ 'mass',
3516
+ 'weight',
3517
+ 'heat',
3518
+ 'cold',
3519
+ 'color',
3520
+ 'tone',
3521
+ 'pitch',
3522
+ 'rhythm',
3523
+ 'vibe',
3524
+ 'mood',
3525
+ 'state',
3526
+ 'way',
3527
+ 'step',
3528
+ 'move',
3529
+ 'turn',
3530
+ 'fall',
3531
+ 'rise',
3532
+ 'jump',
3533
+ 'leap',
3534
+ 'run',
3535
+ 'walk',
3536
+ 'rest',
3537
+ 'stay',
3538
+ 'trip',
3539
+ 'quest',
3540
+ 'task',
3541
+ 'work',
3542
+ 'job',
3543
+ 'play',
3544
+ 'game',
3545
+ 'sport',
3546
+ 'art',
3547
+ 'craft',
3548
+ 'tool',
3549
+ 'ship',
3550
+ 'boat',
3551
+ 'car',
3552
+ 'bike',
3553
+ 'train',
3554
+ 'plane',
3555
+ 'hub',
3556
+ 'base',
3557
+ 'core',
3558
+ 'node',
3559
+ 'link',
3560
+ 'net',
3561
+ 'web',
3562
+ 'box',
3563
+ 'bag',
3564
+ 'jar',
3565
+ 'cup',
3566
+ 'bowl',
3567
+ 'plate',
3568
+ 'dish',
3569
+ 'spoon',
3570
+ 'fork',
3571
+ 'knife',
3572
+ 'pan',
3573
+ 'pot',
3574
+ 'bed',
3575
+ 'desk',
3576
+ 'chair',
3577
+ 'door',
3578
+ 'wall',
3579
+ 'roof',
3580
+ 'floor',
3581
+ ];
3582
+ const VERBS = [
3583
+ 'jumping',
3584
+ 'dancing',
3585
+ 'flying',
3586
+ 'running',
3587
+ 'singing',
3588
+ 'shining',
3589
+ 'growing',
3590
+ 'flowing',
3591
+ 'falling',
3592
+ 'rising',
3593
+ 'sleeping',
3594
+ 'walking',
3595
+ 'talking',
3596
+ 'thinking',
3597
+ 'dreaming',
3598
+ 'looking',
3599
+ 'feeling',
3600
+ 'smiling',
3601
+ 'laughing',
3602
+ 'playing',
3603
+ 'working',
3604
+ 'resting',
3605
+ 'moving',
3606
+ 'staying',
3607
+ 'beaming',
3608
+ 'glowing',
3609
+ 'sparkling',
3610
+ 'waiting',
3611
+ 'waking',
3612
+ 'drifting',
3613
+ 'spinning',
3614
+ 'gliding',
3615
+ 'soaring',
3616
+ 'floating',
3617
+ 'whispering',
3618
+ 'calling',
3619
+ 'seeking',
3620
+ 'finding',
3621
+ 'giving',
3622
+ 'taking',
3623
+ 'weaving',
3624
+ 'building',
3625
+ 'creating',
3626
+ 'burning',
3627
+ 'freezing',
3628
+ 'melting',
3629
+ 'breathing',
3630
+ 'pulsing',
3631
+ 'beating',
3632
+ 'living',
3633
+ 'learning',
3634
+ 'knowing',
3635
+ 'hidden',
3636
+ 'shown',
3637
+ 'broken',
3638
+ 'mended',
3639
+ 'lost',
3640
+ 'found',
3641
+ 'starting',
3642
+ 'ending',
3643
+ 'climbing',
3644
+ 'diving',
3645
+ 'swimming',
3646
+ 'sailing',
3647
+ 'rolling',
3648
+ 'shaking',
3649
+ 'turning',
3650
+ 'shifting',
3651
+ 'changing',
3652
+ 'fading',
3653
+ 'dying',
3654
+ 'born',
3655
+ 'humming',
3656
+ 'crying',
3657
+ 'racing',
3658
+ 'creeping',
3659
+ 'hiding',
3660
+ 'watching',
3661
+ 'hearing',
3662
+ 'sensing',
3663
+ 'longing',
3664
+ 'hoping',
3665
+ 'loving',
3666
+ 'fearing',
3667
+ 'wondering',
3668
+ 'wandering',
3669
+ 'traveling',
3670
+ 'crossing',
3671
+ 'meeting',
3672
+ 'parting',
3673
+ 'keeping',
3674
+ 'sharing',
3675
+ 'sparking',
3676
+ 'flaming',
3677
+ 'healing',
3678
+ 'solving',
3679
+ 'opening',
3680
+ 'closing',
3681
+ 'lifting',
3682
+ 'pulling',
3683
+ 'pushing',
3684
+ 'holding',
3685
+ 'tossing',
3686
+ 'throwing',
3687
+ 'catching',
3688
+ 'fixing',
3689
+ 'making',
3690
+ 'doing',
3691
+ 'seeing',
3692
+ 'tasting',
3693
+ 'smelling',
3694
+ 'touching',
3695
+ 'pacing',
3696
+ 'hurrying',
3697
+ 'pausing',
3698
+ 'going',
3699
+ 'coming',
3700
+ 'leaving',
3701
+ 'acting',
3702
+ 'being',
3703
+ 'seeming',
3704
+ 'shrinking',
3705
+ 'widening',
3706
+ 'narrowing',
3707
+ 'heating',
3708
+ 'cooling',
3709
+ 'drying',
3710
+ 'wetting',
3711
+ 'filling',
3712
+ 'filling',
3713
+ 'emptying',
3714
+ 'letting',
3715
+ 'gaining',
3716
+ 'winning',
3717
+ 'failing',
3718
+ 'trying',
3719
+ 'using',
3720
+ 'getting',
3721
+ 'showing',
3722
+ 'hiding',
3723
+ 'breaking',
3724
+ 'fixing',
3725
+ 'saving',
3726
+ 'spending',
3727
+ 'buying',
3728
+ 'selling',
3729
+ 'paying',
3730
+ 'costing',
3731
+ 'reaching',
3732
+ 'missing',
3733
+ 'hitting',
3734
+ 'striking',
3735
+ 'leading',
3736
+ 'following',
3737
+ 'helping',
3738
+ 'serving',
3739
+ 'teaching',
3740
+ 'training',
3741
+ 'coding',
3742
+ 'writing',
3743
+ 'reading',
3744
+ 'drawing',
3745
+ 'painting',
3746
+ 'crafting',
3747
+ 'shaping',
3748
+ 'forming',
3749
+ 'joining',
3750
+ 'splitting',
3751
+ 'sharing',
3752
+ 'bonding',
3753
+ 'healing',
3754
+ 'harming',
3755
+ 'protecting',
3756
+ 'fighting',
3757
+ 'defending',
3758
+ 'attacking',
3759
+ 'escaping',
3760
+ 'catching',
3761
+ 'trapping',
3762
+ 'freeing',
3763
+ 'binding',
3764
+ 'weaving',
3765
+ 'spinning',
3766
+ ];
3767
+
3065
3768
  /**
3066
3769
  * Function parseNumber will parse number from string
3067
3770
  *
@@ -3134,17 +3837,6 @@
3134
3837
  * TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
3135
3838
  */
3136
3839
 
3137
- /**
3138
- * Makes first letter of a string uppercase
3139
- *
3140
- * Note: [🔂] This function is idempotent.
3141
- *
3142
- * @public exported from `@promptbook/utils`
3143
- */
3144
- function capitalize(word) {
3145
- return word.substring(0, 1).toUpperCase() + word.substring(1);
3146
- }
3147
-
3148
3840
  /**
3149
3841
  * Makes first letter of a string lowercase
3150
3842
  *
@@ -3440,6 +4132,16 @@
3440
4132
  trimmedText = spaceTrim$1.spaceTrim(trimmedText);
3441
4133
  }
3442
4134
  let processedText = trimmedText;
4135
+ // Check for markdown code block
4136
+ const codeBlockRegex = /^```[a-z]*\n([\s\S]*?)\n```\s*$/;
4137
+ const codeBlockMatch = processedText.match(codeBlockRegex);
4138
+ if (codeBlockMatch && codeBlockMatch[1] !== undefined) {
4139
+ // Check if there's only one code block
4140
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
4141
+ if (codeBlockCount === 1) {
4142
+ return unwrapResult(codeBlockMatch[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
4143
+ }
4144
+ }
3443
4145
  if (isIntroduceSentenceRemoved) {
3444
4146
  const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
3445
4147
  if (introduceSentenceRegex.test(text)) {
@@ -3447,6 +4149,14 @@
3447
4149
  processedText = processedText.replace(introduceSentenceRegex, '');
3448
4150
  }
3449
4151
  processedText = spaceTrim$1.spaceTrim(processedText);
4152
+ // Check again for code block after removing introduce sentence
4153
+ const codeBlockMatch2 = processedText.match(codeBlockRegex);
4154
+ if (codeBlockMatch2 && codeBlockMatch2[1] !== undefined) {
4155
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
4156
+ if (codeBlockCount === 1) {
4157
+ return unwrapResult(codeBlockMatch2[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
4158
+ }
4159
+ }
3450
4160
  }
3451
4161
  if (processedText.length < 3) {
3452
4162
  return trimmedText;
@@ -3999,6 +4709,7 @@
3999
4709
  exports.isValidXmlString = isValidXmlString;
4000
4710
  exports.jsonParse = jsonParse;
4001
4711
  exports.jsonStringsToJsons = jsonStringsToJsons;
4712
+ exports.linguisticHash = linguisticHash;
4002
4713
  exports.nameToUriPart = nameToUriPart;
4003
4714
  exports.nameToUriParts = nameToUriParts;
4004
4715
  exports.normalizeMessageText = normalizeMessageText;