@promptbook/core 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/esm/index.es.js CHANGED
@@ -27,7 +27,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-5';
30
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-7';
31
31
  /**
32
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -8525,6 +8525,698 @@ function $getCurrentDate() {
8525
8525
  return new Date().toISOString();
8526
8526
  }
8527
8527
 
8528
+ /**
8529
+ * Creates human-readable hash
8530
+ *
8531
+ * @public exported from `@promptbook/utils`
8532
+ */
8533
+ async function linguisticHash(input) {
8534
+ const hash = computeHash(input);
8535
+ // Use parts of the hash to select words
8536
+ // SHA256 is 64 hex characters
8537
+ // We use different slices of the hash to ensure variety even with small changes in input
8538
+ const part1 = parseInt(hash.substring(0, 10), 16);
8539
+ const part2 = parseInt(hash.substring(10, 20), 16);
8540
+ const part3 = parseInt(hash.substring(20, 30), 16);
8541
+ const adjective = ADJECTIVES[part1 % ADJECTIVES.length];
8542
+ const noun = NOUNS[part2 % NOUNS.length];
8543
+ const verb = VERBS[part3 % VERBS.length];
8544
+ return `${capitalize(adjective)} ${noun.toLowerCase()} ${verb.toLowerCase()}`;
8545
+ }
8546
+ const ADJECTIVES = [
8547
+ 'red',
8548
+ 'blue',
8549
+ 'green',
8550
+ 'yellow',
8551
+ 'quick',
8552
+ 'slow',
8553
+ 'bright',
8554
+ 'dark',
8555
+ 'happy',
8556
+ 'sad',
8557
+ 'brave',
8558
+ 'calm',
8559
+ 'clever',
8560
+ 'eager',
8561
+ 'fancy',
8562
+ 'grand',
8563
+ 'jolly',
8564
+ 'kind',
8565
+ 'lucky',
8566
+ 'nice',
8567
+ 'proud',
8568
+ 'silly',
8569
+ 'wise',
8570
+ 'young',
8571
+ 'old',
8572
+ 'big',
8573
+ 'small',
8574
+ 'fast',
8575
+ 'shiny',
8576
+ 'wild',
8577
+ 'silent',
8578
+ 'loud',
8579
+ 'soft',
8580
+ 'hard',
8581
+ 'warm',
8582
+ 'cold',
8583
+ 'sweet',
8584
+ 'sour',
8585
+ 'bitter',
8586
+ 'salty',
8587
+ 'rich',
8588
+ 'poor',
8589
+ 'heavy',
8590
+ 'light',
8591
+ 'strong',
8592
+ 'weak',
8593
+ 'smooth',
8594
+ 'rough',
8595
+ 'clean',
8596
+ 'dirty',
8597
+ 'fresh',
8598
+ 'stale',
8599
+ 'sharp',
8600
+ 'blunt',
8601
+ 'thick',
8602
+ 'thin',
8603
+ 'wide',
8604
+ 'narrow',
8605
+ 'deep',
8606
+ 'shallow',
8607
+ 'mighty',
8608
+ 'gentle',
8609
+ 'fierce',
8610
+ 'vibrant',
8611
+ 'dusty',
8612
+ 'golden',
8613
+ 'silver',
8614
+ 'frozen',
8615
+ 'burning',
8616
+ 'ancient',
8617
+ 'modern',
8618
+ 'hidden',
8619
+ 'lost',
8620
+ 'found',
8621
+ 'magic',
8622
+ 'mystic',
8623
+ 'cosmic',
8624
+ 'stellar',
8625
+ 'lunar',
8626
+ 'solar',
8627
+ 'misty',
8628
+ 'foggy',
8629
+ 'stormy',
8630
+ 'sunny',
8631
+ 'windy',
8632
+ 'quiet',
8633
+ 'noisy',
8634
+ 'peaceful',
8635
+ 'busy',
8636
+ 'empty',
8637
+ 'full',
8638
+ 'round',
8639
+ 'square',
8640
+ 'flat',
8641
+ 'curved',
8642
+ 'tiny',
8643
+ 'huge',
8644
+ 'giant',
8645
+ 'little',
8646
+ 'short',
8647
+ 'long',
8648
+ 'near',
8649
+ 'distant',
8650
+ 'inner',
8651
+ 'outer',
8652
+ 'patient',
8653
+ 'steady',
8654
+ 'noble',
8655
+ 'pure',
8656
+ 'graceful',
8657
+ 'honest',
8658
+ 'simple',
8659
+ 'complex',
8660
+ 'active',
8661
+ 'passive',
8662
+ 'vivid',
8663
+ 'pale',
8664
+ 'loyal',
8665
+ 'true',
8666
+ 'false',
8667
+ 'fair',
8668
+ 'clear',
8669
+ 'murky',
8670
+ 'vast',
8671
+ 'slick',
8672
+ 'slippery',
8673
+ 'sticky',
8674
+ 'dull',
8675
+ 'keen',
8676
+ 'broad',
8677
+ 'slim',
8678
+ 'slender',
8679
+ 'fat',
8680
+ 'lean',
8681
+ 'stiff',
8682
+ 'flexible',
8683
+ 'rigid',
8684
+ 'elastic',
8685
+ 'tough',
8686
+ 'brittle',
8687
+ 'fragile',
8688
+ 'solid',
8689
+ 'liquid',
8690
+ 'gaseous',
8691
+ 'airy',
8692
+ 'weighty',
8693
+ 'buoyant',
8694
+ 'dense',
8695
+ 'sparse',
8696
+ 'hollow',
8697
+ 'stuffed',
8698
+ 'crowded',
8699
+ 'lonely',
8700
+ 'social',
8701
+ 'private',
8702
+ 'public',
8703
+ 'secret',
8704
+ 'famous',
8705
+ 'certain',
8706
+ 'vague',
8707
+ 'plain',
8708
+ 'easy',
8709
+ 'tame',
8710
+ 'mild',
8711
+ 'hot',
8712
+ 'cool',
8713
+ 'dry',
8714
+ 'wet',
8715
+ 'damp',
8716
+ 'moist',
8717
+ 'soaked',
8718
+ 'parched',
8719
+ 'hungry',
8720
+ 'thirsty',
8721
+ 'sleepy',
8722
+ 'awake',
8723
+ 'tired',
8724
+ 'lazy',
8725
+ 'idle',
8726
+ 'swift',
8727
+ 'rapid',
8728
+ 'unstable',
8729
+ 'shaky',
8730
+ 'firm',
8731
+ 'bold',
8732
+ 'timid',
8733
+ 'brave',
8734
+ 'cowardly',
8735
+ 'smart',
8736
+ 'dumb',
8737
+ 'foolish',
8738
+ 'mean',
8739
+ 'rude',
8740
+ 'tasty',
8741
+ 'bland',
8742
+ 'arctic',
8743
+ 'tropical',
8744
+ 'deserted',
8745
+ 'urban',
8746
+ 'rural',
8747
+ 'local',
8748
+ 'global',
8749
+ 'digital',
8750
+ 'analog',
8751
+ 'virtual',
8752
+ 'real',
8753
+ 'fake',
8754
+ 'natural',
8755
+ 'artificial',
8756
+ 'living',
8757
+ 'dead',
8758
+ 'broken',
8759
+ 'fixed',
8760
+ 'new',
8761
+ 'worn',
8762
+ 'neat',
8763
+ 'messy',
8764
+ 'brave',
8765
+ 'fearful',
8766
+ 'proud',
8767
+ 'humble',
8768
+ 'greedy',
8769
+ 'generous',
8770
+ 'calm',
8771
+ 'angry',
8772
+ 'happy',
8773
+ 'sad',
8774
+ 'excited',
8775
+ 'bored',
8776
+ 'strange',
8777
+ 'normal',
8778
+ 'odd',
8779
+ 'even',
8780
+ 'rare',
8781
+ 'common',
8782
+ 'unique',
8783
+ 'plain',
8784
+ 'fancy',
8785
+ 'basic',
8786
+ 'prime',
8787
+ 'super',
8788
+ 'mega',
8789
+ 'ultra',
8790
+ 'micro',
8791
+ 'nano',
8792
+ 'macro',
8793
+ 'mini',
8794
+ ];
8795
+ const NOUNS = [
8796
+ 'apple',
8797
+ 'sky',
8798
+ 'tree',
8799
+ 'fox',
8800
+ 'cat',
8801
+ 'bird',
8802
+ 'dog',
8803
+ 'river',
8804
+ 'mountain',
8805
+ 'forest',
8806
+ 'ocean',
8807
+ 'star',
8808
+ 'moon',
8809
+ 'sun',
8810
+ 'cloud',
8811
+ 'flower',
8812
+ 'leaf',
8813
+ 'stone',
8814
+ 'wind',
8815
+ 'rain',
8816
+ 'fire',
8817
+ 'ice',
8818
+ 'book',
8819
+ 'dream',
8820
+ 'song',
8821
+ 'road',
8822
+ 'gate',
8823
+ 'key',
8824
+ 'lamp',
8825
+ 'map',
8826
+ 'house',
8827
+ 'city',
8828
+ 'bridge',
8829
+ 'field',
8830
+ 'garden',
8831
+ 'lake',
8832
+ 'beach',
8833
+ 'island',
8834
+ 'valley',
8835
+ 'desert',
8836
+ 'world',
8837
+ 'spirit',
8838
+ 'heart',
8839
+ 'mind',
8840
+ 'soul',
8841
+ 'life',
8842
+ 'time',
8843
+ 'space',
8844
+ 'light',
8845
+ 'shadow',
8846
+ 'sound',
8847
+ 'music',
8848
+ 'voice',
8849
+ 'word',
8850
+ 'page',
8851
+ 'story',
8852
+ 'pearl',
8853
+ 'gold',
8854
+ 'silver',
8855
+ 'crystal',
8856
+ 'diamond',
8857
+ 'emerald',
8858
+ 'ruby',
8859
+ 'path',
8860
+ 'trail',
8861
+ 'peak',
8862
+ 'shore',
8863
+ 'wave',
8864
+ 'tide',
8865
+ 'flame',
8866
+ 'spark',
8867
+ 'beam',
8868
+ 'ray',
8869
+ 'seed',
8870
+ 'root',
8871
+ 'branch',
8872
+ 'bloom',
8873
+ 'thorn',
8874
+ 'bark',
8875
+ 'shell',
8876
+ 'feather',
8877
+ 'wing',
8878
+ 'claw',
8879
+ 'paw',
8880
+ 'nest',
8881
+ 'cave',
8882
+ 'grove',
8883
+ 'tower',
8884
+ 'castle',
8885
+ 'crown',
8886
+ 'sword',
8887
+ 'shield',
8888
+ 'coin',
8889
+ 'gem',
8890
+ 'ring',
8891
+ 'bell',
8892
+ 'clock',
8893
+ 'compass',
8894
+ 'anchor',
8895
+ 'torch',
8896
+ 'flute',
8897
+ 'harp',
8898
+ 'drum',
8899
+ 'lens',
8900
+ 'glass',
8901
+ 'sand',
8902
+ 'dust',
8903
+ 'mist',
8904
+ 'dew',
8905
+ 'dawn',
8906
+ 'dusk',
8907
+ 'night',
8908
+ 'day',
8909
+ 'year',
8910
+ 'age',
8911
+ 'bolt',
8912
+ 'drop',
8913
+ 'storm',
8914
+ 'snow',
8915
+ 'hail',
8916
+ 'fog',
8917
+ 'smoke',
8918
+ 'vapor',
8919
+ 'gas',
8920
+ 'fluid',
8921
+ 'liquid',
8922
+ 'solid',
8923
+ 'metal',
8924
+ 'rock',
8925
+ 'dirt',
8926
+ 'clay',
8927
+ 'sand',
8928
+ 'salt',
8929
+ 'sugar',
8930
+ 'wood',
8931
+ 'bone',
8932
+ 'skin',
8933
+ 'flesh',
8934
+ 'blood',
8935
+ 'cell',
8936
+ 'atom',
8937
+ 'pulse',
8938
+ 'beat',
8939
+ 'breath',
8940
+ 'sigh',
8941
+ 'name',
8942
+ 'echo',
8943
+ 'image',
8944
+ 'vision',
8945
+ 'thought',
8946
+ 'idea',
8947
+ 'plan',
8948
+ 'goal',
8949
+ 'wish',
8950
+ 'hope',
8951
+ 'fear',
8952
+ 'joy',
8953
+ 'love',
8954
+ 'hate',
8955
+ 'will',
8956
+ 'power',
8957
+ 'force',
8958
+ 'energy',
8959
+ 'motion',
8960
+ 'speed',
8961
+ 'place',
8962
+ 'point',
8963
+ 'line',
8964
+ 'shape',
8965
+ 'form',
8966
+ 'size',
8967
+ 'mass',
8968
+ 'weight',
8969
+ 'heat',
8970
+ 'cold',
8971
+ 'color',
8972
+ 'tone',
8973
+ 'pitch',
8974
+ 'rhythm',
8975
+ 'vibe',
8976
+ 'mood',
8977
+ 'state',
8978
+ 'way',
8979
+ 'step',
8980
+ 'move',
8981
+ 'turn',
8982
+ 'fall',
8983
+ 'rise',
8984
+ 'jump',
8985
+ 'leap',
8986
+ 'run',
8987
+ 'walk',
8988
+ 'rest',
8989
+ 'stay',
8990
+ 'trip',
8991
+ 'quest',
8992
+ 'task',
8993
+ 'work',
8994
+ 'job',
8995
+ 'play',
8996
+ 'game',
8997
+ 'sport',
8998
+ 'art',
8999
+ 'craft',
9000
+ 'tool',
9001
+ 'ship',
9002
+ 'boat',
9003
+ 'car',
9004
+ 'bike',
9005
+ 'train',
9006
+ 'plane',
9007
+ 'hub',
9008
+ 'base',
9009
+ 'core',
9010
+ 'node',
9011
+ 'link',
9012
+ 'net',
9013
+ 'web',
9014
+ 'box',
9015
+ 'bag',
9016
+ 'jar',
9017
+ 'cup',
9018
+ 'bowl',
9019
+ 'plate',
9020
+ 'dish',
9021
+ 'spoon',
9022
+ 'fork',
9023
+ 'knife',
9024
+ 'pan',
9025
+ 'pot',
9026
+ 'bed',
9027
+ 'desk',
9028
+ 'chair',
9029
+ 'door',
9030
+ 'wall',
9031
+ 'roof',
9032
+ 'floor',
9033
+ ];
9034
+ const VERBS = [
9035
+ 'jumping',
9036
+ 'dancing',
9037
+ 'flying',
9038
+ 'running',
9039
+ 'singing',
9040
+ 'shining',
9041
+ 'growing',
9042
+ 'flowing',
9043
+ 'falling',
9044
+ 'rising',
9045
+ 'sleeping',
9046
+ 'walking',
9047
+ 'talking',
9048
+ 'thinking',
9049
+ 'dreaming',
9050
+ 'looking',
9051
+ 'feeling',
9052
+ 'smiling',
9053
+ 'laughing',
9054
+ 'playing',
9055
+ 'working',
9056
+ 'resting',
9057
+ 'moving',
9058
+ 'staying',
9059
+ 'beaming',
9060
+ 'glowing',
9061
+ 'sparkling',
9062
+ 'waiting',
9063
+ 'waking',
9064
+ 'drifting',
9065
+ 'spinning',
9066
+ 'gliding',
9067
+ 'soaring',
9068
+ 'floating',
9069
+ 'whispering',
9070
+ 'calling',
9071
+ 'seeking',
9072
+ 'finding',
9073
+ 'giving',
9074
+ 'taking',
9075
+ 'weaving',
9076
+ 'building',
9077
+ 'creating',
9078
+ 'burning',
9079
+ 'freezing',
9080
+ 'melting',
9081
+ 'breathing',
9082
+ 'pulsing',
9083
+ 'beating',
9084
+ 'living',
9085
+ 'learning',
9086
+ 'knowing',
9087
+ 'hidden',
9088
+ 'shown',
9089
+ 'broken',
9090
+ 'mended',
9091
+ 'lost',
9092
+ 'found',
9093
+ 'starting',
9094
+ 'ending',
9095
+ 'climbing',
9096
+ 'diving',
9097
+ 'swimming',
9098
+ 'sailing',
9099
+ 'rolling',
9100
+ 'shaking',
9101
+ 'turning',
9102
+ 'shifting',
9103
+ 'changing',
9104
+ 'fading',
9105
+ 'dying',
9106
+ 'born',
9107
+ 'humming',
9108
+ 'crying',
9109
+ 'racing',
9110
+ 'creeping',
9111
+ 'hiding',
9112
+ 'watching',
9113
+ 'hearing',
9114
+ 'sensing',
9115
+ 'longing',
9116
+ 'hoping',
9117
+ 'loving',
9118
+ 'fearing',
9119
+ 'wondering',
9120
+ 'wandering',
9121
+ 'traveling',
9122
+ 'crossing',
9123
+ 'meeting',
9124
+ 'parting',
9125
+ 'keeping',
9126
+ 'sharing',
9127
+ 'sparking',
9128
+ 'flaming',
9129
+ 'healing',
9130
+ 'solving',
9131
+ 'opening',
9132
+ 'closing',
9133
+ 'lifting',
9134
+ 'pulling',
9135
+ 'pushing',
9136
+ 'holding',
9137
+ 'tossing',
9138
+ 'throwing',
9139
+ 'catching',
9140
+ 'fixing',
9141
+ 'making',
9142
+ 'doing',
9143
+ 'seeing',
9144
+ 'tasting',
9145
+ 'smelling',
9146
+ 'touching',
9147
+ 'pacing',
9148
+ 'hurrying',
9149
+ 'pausing',
9150
+ 'going',
9151
+ 'coming',
9152
+ 'leaving',
9153
+ 'acting',
9154
+ 'being',
9155
+ 'seeming',
9156
+ 'shrinking',
9157
+ 'widening',
9158
+ 'narrowing',
9159
+ 'heating',
9160
+ 'cooling',
9161
+ 'drying',
9162
+ 'wetting',
9163
+ 'filling',
9164
+ 'filling',
9165
+ 'emptying',
9166
+ 'letting',
9167
+ 'gaining',
9168
+ 'winning',
9169
+ 'failing',
9170
+ 'trying',
9171
+ 'using',
9172
+ 'getting',
9173
+ 'showing',
9174
+ 'hiding',
9175
+ 'breaking',
9176
+ 'fixing',
9177
+ 'saving',
9178
+ 'spending',
9179
+ 'buying',
9180
+ 'selling',
9181
+ 'paying',
9182
+ 'costing',
9183
+ 'reaching',
9184
+ 'missing',
9185
+ 'hitting',
9186
+ 'striking',
9187
+ 'leading',
9188
+ 'following',
9189
+ 'helping',
9190
+ 'serving',
9191
+ 'teaching',
9192
+ 'training',
9193
+ 'coding',
9194
+ 'writing',
9195
+ 'reading',
9196
+ 'drawing',
9197
+ 'painting',
9198
+ 'crafting',
9199
+ 'shaping',
9200
+ 'forming',
9201
+ 'joining',
9202
+ 'splitting',
9203
+ 'sharing',
9204
+ 'bonding',
9205
+ 'healing',
9206
+ 'harming',
9207
+ 'protecting',
9208
+ 'fighting',
9209
+ 'defending',
9210
+ 'attacking',
9211
+ 'escaping',
9212
+ 'catching',
9213
+ 'trapping',
9214
+ 'freeing',
9215
+ 'binding',
9216
+ 'weaving',
9217
+ 'spinning',
9218
+ ];
9219
+
8528
9220
  /**
8529
9221
  * Function parseNumber will parse number from string
8530
9222
  *
@@ -8633,6 +9325,95 @@ function removeQuotes(text) {
8633
9325
  return text;
8634
9326
  }
8635
9327
 
9328
+ /**
9329
+ * Removes quotes and optional introduce text from a string
9330
+ *
9331
+ * Tip: This is very useful for post-processing of the result of the LLM model
9332
+ * Note: This function trims the text and removes whole introduce sentence if it is present
9333
+ * Note: There are two similar functions:
9334
+ * - `removeQuotes` which removes only bounding quotes
9335
+ * - `unwrapResult` which removes whole introduce sentence
9336
+ *
9337
+ * @param text optionally quoted text
9338
+ * @returns text without quotes
9339
+ * @public exported from `@promptbook/utils`
9340
+ */
9341
+ function unwrapResult(text, options) {
9342
+ const { isTrimmed = true, isIntroduceSentenceRemoved = true } = options || {};
9343
+ let trimmedText = text;
9344
+ // Remove leading and trailing spaces and newlines
9345
+ if (isTrimmed) {
9346
+ trimmedText = spaceTrim$1(trimmedText);
9347
+ }
9348
+ let processedText = trimmedText;
9349
+ // Check for markdown code block
9350
+ const codeBlockRegex = /^```[a-z]*\n([\s\S]*?)\n```\s*$/;
9351
+ const codeBlockMatch = processedText.match(codeBlockRegex);
9352
+ if (codeBlockMatch && codeBlockMatch[1] !== undefined) {
9353
+ // Check if there's only one code block
9354
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
9355
+ if (codeBlockCount === 1) {
9356
+ return unwrapResult(codeBlockMatch[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
9357
+ }
9358
+ }
9359
+ if (isIntroduceSentenceRemoved) {
9360
+ const introduceSentenceRegex = /^[a-zěščřžýáíéúů:\s]*:\s*/i;
9361
+ if (introduceSentenceRegex.test(text)) {
9362
+ // Remove the introduce sentence and quotes by replacing it with an empty string
9363
+ processedText = processedText.replace(introduceSentenceRegex, '');
9364
+ }
9365
+ processedText = spaceTrim$1(processedText);
9366
+ // Check again for code block after removing introduce sentence
9367
+ const codeBlockMatch2 = processedText.match(codeBlockRegex);
9368
+ if (codeBlockMatch2 && codeBlockMatch2[1] !== undefined) {
9369
+ const codeBlockCount = (processedText.match(/```/g) || []).length / 2;
9370
+ if (codeBlockCount === 1) {
9371
+ return unwrapResult(codeBlockMatch2[1], { isTrimmed: false, isIntroduceSentenceRemoved: false });
9372
+ }
9373
+ }
9374
+ }
9375
+ if (processedText.length < 3) {
9376
+ return trimmedText;
9377
+ }
9378
+ if (processedText.includes('\n')) {
9379
+ return trimmedText;
9380
+ }
9381
+ // Remove the quotes by extracting the substring without the first and last characters
9382
+ const unquotedText = processedText.slice(1, -1);
9383
+ // Check if the text starts and ends with quotes
9384
+ if ([
9385
+ ['"', '"'],
9386
+ ["'", "'"],
9387
+ ['`', '`'],
9388
+ ['*', '*'],
9389
+ ['_', '_'],
9390
+ ['„', '“'],
9391
+ ['«', '»'] /* <- QUOTES to config */,
9392
+ ].some(([startQuote, endQuote]) => {
9393
+ if (!processedText.startsWith(startQuote)) {
9394
+ return false;
9395
+ }
9396
+ if (!processedText.endsWith(endQuote)) {
9397
+ return false;
9398
+ }
9399
+ if (unquotedText.includes(startQuote) && !unquotedText.includes(endQuote)) {
9400
+ return false;
9401
+ }
9402
+ if (!unquotedText.includes(startQuote) && unquotedText.includes(endQuote)) {
9403
+ return false;
9404
+ }
9405
+ return true;
9406
+ })) {
9407
+ return unwrapResult(unquotedText, { isTrimmed: false, isIntroduceSentenceRemoved: false });
9408
+ }
9409
+ else {
9410
+ return processedText;
9411
+ }
9412
+ }
9413
+ /**
9414
+ * TODO: [🧠] Should this also unwrap the (parenthesis)
9415
+ */
9416
+
8636
9417
  /**
8637
9418
  * Checks if the given value is a valid JavaScript identifier name.
8638
9419
  *
@@ -11671,6 +12452,7 @@ const COMMITMENT_REGISTRY = [
11671
12452
  new NoteCommitmentDefinition('NOTES'),
11672
12453
  new NoteCommitmentDefinition('COMMENT'),
11673
12454
  new NoteCommitmentDefinition('NONCE'),
12455
+ new NoteCommitmentDefinition('TODO'),
11674
12456
  new GoalCommitmentDefinition('GOAL'),
11675
12457
  new GoalCommitmentDefinition('GOALS'),
11676
12458
  new InitialMessageCommitmentDefinition(),
@@ -20541,8 +21323,7 @@ AgentLlmExecutionTools.assistantCache = new Map();
20541
21323
  * TODO: [🧠] Adding parameter substitution support (here or should be responsibility of the underlying LLM Tools)
20542
21324
  */
20543
21325
 
20544
- var _Agent_instances, _Agent_selfLearnSamples;
20545
- // !!!!! import { RemoteAgent } from './RemoteAgent'; // <- [💞] <- !!!!!
21326
+ var _Agent_instances, _Agent_selfLearnNonce, _Agent_selfLearnSamples, _Agent_selfLearnTeacher;
20546
21327
  /**
20547
21328
  * Represents one AI Agent
20548
21329
  *
@@ -20612,6 +21393,7 @@ class Agent extends AgentLlmExecutionTools {
20612
21393
  this.meta = {};
20613
21394
  // TODO: [🐱‍🚀] Add `Agent` simple "mocked" learning by appending to agent source
20614
21395
  // TODO: [🐱‍🚀] Add `Agent` learning by promptbookAgent
21396
+ this.teacherAgent = options.teacherAgent;
20615
21397
  this.agentSource = agentSource;
20616
21398
  this.agentSource.subscribe((source) => {
20617
21399
  this.updateAgentSource(source);
@@ -20682,26 +21464,41 @@ class Agent extends AgentLlmExecutionTools {
20682
21464
  if ((_a = modelRequirements.metadata) === null || _a === void 0 ? void 0 : _a.isClosed) {
20683
21465
  return result;
20684
21466
  }
20685
- // TODO: !!!!! Is this timed properly?
21467
+ // TODO: !!!!! Return the answer and do the learning asynchronously
21468
+ // Note: [0] Asynchronously add nonce
21469
+ if (just(false)) {
21470
+ await __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnNonce).call(this);
21471
+ }
20686
21472
  // Note: [1] Do the append of the samples
20687
- __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnSamples).call(this, prompt, result);
20688
- /*
20689
- !!!!!
21473
+ await __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnSamples).call(this, prompt, result);
20690
21474
  // Note: [2] Asynchronously call the teacher agent and invoke the silver link. When the teacher fails, keep just the samples
20691
- this.#selfLearnTeacher(prompt, result).catch((error) => {
20692
- if (this.options.isVerbose) {
20693
- console.error('Failed to self-learn from teacher agent', error);
20694
- }
21475
+ await __classPrivateFieldGet(this, _Agent_instances, "m", _Agent_selfLearnTeacher).call(this, prompt, result).catch((error) => {
21476
+ // !!!!! if (this.options.isVerbose) {
21477
+ console.error(colors.bgCyan('[Self-learning]') + colors.red(' Failed to learn from teacher agent'));
21478
+ console.error(error);
21479
+ // }
20695
21480
  });
20696
- */
20697
21481
  return result;
20698
21482
  }
20699
21483
  }
20700
- _Agent_instances = new WeakSet(), _Agent_selfLearnSamples = function _Agent_selfLearnSamples(prompt, result) {
21484
+ _Agent_instances = new WeakSet(), _Agent_selfLearnNonce =
21485
+ /**
21486
+ * Self-learning Step 0: Asynchronously with random timing add nonce to the agent source
21487
+ */
21488
+ async function _Agent_selfLearnNonce() {
21489
+ await forTime(Math.random() * 5000);
21490
+ console.info(colors.bgCyan('[Self-learning]') + colors.cyan(' Nonce'));
21491
+ const nonce = `NONCE ${await linguisticHash(Math.random().toString())}`;
21492
+ // Append to the current source
21493
+ const currentSource = this.agentSource.value;
21494
+ const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n---\n\n' + nonce));
21495
+ // <- TODO: [🈲] Use some object-based way how to append on book (with sections `---`)
21496
+ // Update the source (which will trigger the subscription and update the underlying tools)
21497
+ this.agentSource.next(newSource);
21498
+ }, _Agent_selfLearnSamples = function _Agent_selfLearnSamples(prompt, result) {
21499
+ console.info(colors.bgCyan('[Self-learning]') + colors.cyan(' Sampling'));
20701
21500
  const learningExample = spaceTrim$2((block) => `
20702
21501
 
20703
- ---
20704
-
20705
21502
  USER MESSAGE
20706
21503
  ${block(prompt.content)}
20707
21504
 
@@ -20711,9 +21508,80 @@ _Agent_instances = new WeakSet(), _Agent_selfLearnSamples = function _Agent_self
20711
21508
  `);
20712
21509
  // Append to the current source
20713
21510
  const currentSource = this.agentSource.value;
20714
- const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n' + learningExample));
21511
+ const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n---\n\n' + learningExample));
21512
+ // <- TODO: [🈲] Use some object-based way how to append on book (with sections `---`)
20715
21513
  // Update the source (which will trigger the subscription and update the underlying tools)
20716
21514
  this.agentSource.next(newSource);
21515
+ }, _Agent_selfLearnTeacher =
21516
+ /**
21517
+ * Self-learning Step 2: Asynchronously call the teacher agent and invoke the silver link
21518
+ */
21519
+ async function _Agent_selfLearnTeacher(prompt, result) {
21520
+ // [1] Call the teacher agent // <- !!!!! Emojis
21521
+ if (this.teacherAgent === null) {
21522
+ return;
21523
+ }
21524
+ console.info(colors.bgCyan('[Self-learning]') + colors.cyan(' Teacher'));
21525
+ const teacherResult = await this.teacherAgent.callChatModel({
21526
+ title: 'Self-learning',
21527
+ modelRequirements: {
21528
+ modelVariant: 'CHAT',
21529
+ },
21530
+ // TODO: !!!! Use prompt notation
21531
+ content: spaceTrim$2((block) => `
21532
+
21533
+ You are a teacher agent helping another agent to learn from its interactions.
21534
+
21535
+ Here is your current client which you are teaching:
21536
+
21537
+ \`\`\`book
21538
+ ${block(this.agentSource.value)}
21539
+ \`\`\`
21540
+
21541
+ **And here is the latest interaction:**
21542
+
21543
+ **User:**
21544
+ ${block(prompt.content)}
21545
+
21546
+ **Agent:**
21547
+ ${block(result.content)}
21548
+
21549
+
21550
+ **Rules:**
21551
+
21552
+ - Decide what the agent should learn from this interaction.
21553
+ - Append new commitments at the end of the agent source.
21554
+ - Do not modify the current agent source, just return new commitments (KNOWLEDGE, RULE, etc.).
21555
+ - If there is nothing new to learn, return empty book code block
21556
+ - Wrap the commitments in a book code block.
21557
+ - Do not explain anything, just return the commitments wrapped in a book code block.
21558
+ - Write the learned commitments in the same style and language as in the original agent source.
21559
+
21560
+
21561
+ This is how book code block looks like:
21562
+
21563
+ \`\`\`book
21564
+ KNOWLEDGE The sky is blue.
21565
+ RULE Always be polite.
21566
+ \`\`\`
21567
+ `),
21568
+ // pipelineUrl: 'https://github.com/webgptorg/promptbook/blob/main/prompts/self-learning.ptbk.md',
21569
+ // <- TODO: !!!! Remove and `pipelineUrl` for agent purposes
21570
+ parameters: {},
21571
+ });
21572
+ console.log('!!!! teacherResult', teacherResult);
21573
+ const teacherCommitments = unwrapResult(teacherResult.content);
21574
+ if (teacherCommitments === '') {
21575
+ console.info(colors.bgCyan('[Self-learning]') +
21576
+ colors.cyan(' Teacher agent did not provide new commitments to learn'));
21577
+ return;
21578
+ }
21579
+ // [2] Append to the current source
21580
+ const currentSource = this.agentSource.value;
21581
+ const newSource = padBook(validateBook(spaceTrim$2(currentSource) + '\n\n' + teacherCommitments));
21582
+ // <- TODO: [🈲] Use some object-based way how to append on book (with sections `---`)
21583
+ // [3] Update the source
21584
+ this.agentSource.next(newSource);
20717
21585
  };
20718
21586
  /**
20719
21587
  * TODO: [🧠][😰]Agent is not working with the parameters, should it be?
@@ -20857,10 +21725,25 @@ function book(strings, ...values) {
20857
21725
  */
20858
21726
  class RemoteAgent extends Agent {
20859
21727
  static async connect(options) {
20860
- console.log('[🐱‍🚀]', `${options.agentUrl}/api/profile`);
20861
- const profileResponse = await fetch(`${options.agentUrl}/api/profile`);
21728
+ const agentProfileUrl = `${options.agentUrl}/api/profile`;
21729
+ const profileResponse = await fetch(agentProfileUrl);
20862
21730
  // <- TODO: [🐱‍🚀] What about closed-source agents?
20863
21731
  // <- TODO: [🐱‍🚀] Maybe use promptbookFetch
21732
+ if (!profileResponse.ok) {
21733
+ throw new Error(spaceTrim$2((block) => `
21734
+ Failed to fetch remote agent profile:
21735
+
21736
+ Agent URL:
21737
+ ${options.agentUrl}
21738
+
21739
+ Agent Profile URL:
21740
+ ${agentProfileUrl}
21741
+
21742
+ Http Error:
21743
+ ${block(profileResponse.statusText)}
21744
+
21745
+ `));
21746
+ }
20864
21747
  const profile = await profileResponse.json();
20865
21748
  // Note: We are creating dummy agent source because we don't have the source from the remote agent
20866
21749
  // But we populate the metadata from the profile
@@ -20887,6 +21770,7 @@ class RemoteAgent extends Agent {
20887
21770
  */
20888
21771
  },
20889
21772
  agentSource,
21773
+ teacherAgent: null, // <- Note:
20890
21774
  });
20891
21775
  remoteAgent._remoteAgentName = profile.agentName;
20892
21776
  remoteAgent._remoteAgentHash = profile.agentHash;
@@ -22626,10 +23510,11 @@ function $generateBookBoilerplate(options) {
22626
23510
  const agentSource = validateBook(spaceTrim$2((block) => `
22627
23511
  ${agentName}
22628
23512
 
22629
- META COLOR ${color || PROMPTBOOK_COLOR.toHex()}
23513
+
22630
23514
  PERSONA ${block(personaDescription)}
22631
23515
  ${block(initialRules.map((rule) => `RULE ${rule}`).join('\n'))}
22632
23516
  `));
23517
+ // Note: `META COLOR ${color || PROMPTBOOK_COLOR.toHex()}` was removed for now
22633
23518
  // Note: `META FONT Playfair Display, sans-serif` was removed for now
22634
23519
  // <- TODO: [🈲] Simple and object-constructive way how to create new books
22635
23520
  return agentSource;