@promptbook/editable 0.103.0-54 → 0.103.0-56

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
@@ -1,4 +1,4 @@
1
- import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
1
+ import spaceTrim$2, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
2
  import { parse, unparse } from 'papaparse';
3
3
  import { SHA256 } from 'crypto-js';
4
4
  import hexEncoder from 'crypto-js/enc-hex';
@@ -17,12 +17,23 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
17
17
  * @generated
18
18
  * @see https://github.com/webgptorg/promptbook
19
19
  */
20
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-54';
20
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-56';
21
21
  /**
22
22
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
23
23
  * Note: [💞] Ignore a discrepancy between file name and entity name
24
24
  */
25
25
 
26
+ /**
27
+ * Trims string from all 4 sides
28
+ *
29
+ * Note: This is a re-exported function from the `spacetrim` package which is
30
+ * Developed by same author @hejny as this package
31
+ *
32
+ * @public exported from `@promptbook/utils`
33
+ * @see https://github.com/hejny/spacetrim#usage
34
+ */
35
+ const spaceTrim = spaceTrim$1;
36
+
26
37
  /**
27
38
  * @private util of `@promptbook/color`
28
39
  * @de
@@ -71,6 +82,7 @@ function take(initialValue) {
71
82
  * @public exported from `@promptbook/color`
72
83
  */
73
84
  const CSS_COLORS = {
85
+ promptbook: '#79EAFD',
74
86
  transparent: 'rgba(0,0,0,0)',
75
87
  aliceblue: '#f0f8ff',
76
88
  antiquewhite: '#faebd7',
@@ -286,6 +298,28 @@ class Color {
286
298
  throw new Error(`Can not create color from given object`);
287
299
  }
288
300
  }
301
+ /**
302
+ * Creates a new Color instance from miscellaneous formats
303
+ * It just does not throw error when it fails, it returns PROMPTBOOK_COLOR instead
304
+ *
305
+ * @param color
306
+ * @returns Color object
307
+ */
308
+ static fromSafe(color) {
309
+ try {
310
+ return Color.from(color);
311
+ }
312
+ catch (error) {
313
+ // <- Note: Can not use `assertsError(error)` here because it causes circular dependency
314
+ console.warn(spaceTrim((block) => `
315
+ Color.fromSafe error:
316
+ ${block(error.message)}
317
+
318
+ Returning default PROMPTBOOK_COLOR.
319
+ `));
320
+ return Color.fromString('promptbook');
321
+ }
322
+ }
289
323
  /**
290
324
  * Creates a new Color instance from miscellaneous string formats
291
325
  *
@@ -895,7 +929,7 @@ const ADMIN_GITHUB_NAME = 'hejny';
895
929
  *
896
930
  * @public exported from `@promptbook/core`
897
931
  */
898
- const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
932
+ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
899
933
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
900
934
  /**
901
935
  * Colors for syntax highlighting in the `<BookEditor/>`
@@ -981,7 +1015,7 @@ parseInt(process.env.API_REQUEST_TIMEOUT || '90000');
981
1015
  function getErrorReportUrl(error) {
982
1016
  const report = {
983
1017
  title: `🐜 Error report from ${NAME}`,
984
- body: spaceTrim((block) => `
1018
+ body: spaceTrim$2((block) => `
985
1019
 
986
1020
 
987
1021
  \`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
@@ -1440,7 +1474,7 @@ const expectCommandParser = {
1440
1474
  /**
1441
1475
  * Description of the FORMAT command
1442
1476
  */
1443
- description: spaceTrim(`
1477
+ description: spaceTrim$2(`
1444
1478
  Expect command describes the desired output of the task *(after post-processing)*
1445
1479
  It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.
1446
1480
  `),
@@ -1514,7 +1548,7 @@ const expectCommandParser = {
1514
1548
  }
1515
1549
  catch (error) {
1516
1550
  assertsError(error);
1517
- throw new ParseError(spaceTrim((block) => `
1551
+ throw new ParseError(spaceTrim$2((block) => `
1518
1552
  Invalid FORMAT command
1519
1553
  ${block(error.message)}:
1520
1554
  `));
@@ -1666,7 +1700,7 @@ const CsvFormatParser = {
1666
1700
  const { value, outputParameterName, settings, mapCallback, onProgress } = options;
1667
1701
  const csv = csvParse(value, settings);
1668
1702
  if (csv.errors.length !== 0) {
1669
- throw new CsvFormatError(spaceTrim((block) => `
1703
+ throw new CsvFormatError(spaceTrim$2((block) => `
1670
1704
  CSV parsing error
1671
1705
 
1672
1706
  Error(s) from CSV parsing:
@@ -1711,7 +1745,7 @@ const CsvFormatParser = {
1711
1745
  const { value, settings, mapCallback, onProgress } = options;
1712
1746
  const csv = csvParse(value, settings);
1713
1747
  if (csv.errors.length !== 0) {
1714
- throw new CsvFormatError(spaceTrim((block) => `
1748
+ throw new CsvFormatError(spaceTrim$2((block) => `
1715
1749
  CSV parsing error
1716
1750
 
1717
1751
  Error(s) from CSV parsing:
@@ -2056,7 +2090,7 @@ function checkSerializableAsJson(options) {
2056
2090
  }
2057
2091
  else if (typeof value === 'object') {
2058
2092
  if (value instanceof Date) {
2059
- throw new UnexpectedError(spaceTrim((block) => `
2093
+ throw new UnexpectedError(spaceTrim$2((block) => `
2060
2094
  \`${name}\` is Date
2061
2095
 
2062
2096
  Use \`string_date_iso8601\` instead
@@ -2075,7 +2109,7 @@ function checkSerializableAsJson(options) {
2075
2109
  throw new UnexpectedError(`${name} is RegExp`);
2076
2110
  }
2077
2111
  else if (value instanceof Error) {
2078
- throw new UnexpectedError(spaceTrim((block) => `
2112
+ throw new UnexpectedError(spaceTrim$2((block) => `
2079
2113
  \`${name}\` is unserialized Error
2080
2114
 
2081
2115
  Use function \`serializeError\`
@@ -2098,7 +2132,7 @@ function checkSerializableAsJson(options) {
2098
2132
  }
2099
2133
  catch (error) {
2100
2134
  assertsError(error);
2101
- throw new UnexpectedError(spaceTrim((block) => `
2135
+ throw new UnexpectedError(spaceTrim$2((block) => `
2102
2136
  \`${name}\` is not serializable
2103
2137
 
2104
2138
  ${block(error.stack || error.message)}
@@ -2130,7 +2164,7 @@ function checkSerializableAsJson(options) {
2130
2164
  }
2131
2165
  }
2132
2166
  else {
2133
- throw new UnexpectedError(spaceTrim((block) => `
2167
+ throw new UnexpectedError(spaceTrim$2((block) => `
2134
2168
  \`${name}\` is unknown type
2135
2169
 
2136
2170
  Additional message for \`${name}\`:
@@ -2660,7 +2694,7 @@ function validateParameterName(parameterName) {
2660
2694
  if (!(error instanceof ParseError)) {
2661
2695
  throw error;
2662
2696
  }
2663
- throw new ParseError(spaceTrim((block) => `
2697
+ throw new ParseError(spaceTrim$2((block) => `
2664
2698
  ${block(error.message)}
2665
2699
 
2666
2700
  Tried to validate parameter name:
@@ -2719,7 +2753,7 @@ const foreachCommandParser = {
2719
2753
  const assignSign = args[3];
2720
2754
  const formatDefinition = FORMAT_DEFINITIONS.find((formatDefinition) => [formatDefinition.formatName, ...(formatDefinition.aliases || [])].includes(formatName));
2721
2755
  if (formatDefinition === undefined) {
2722
- throw new ParseError(spaceTrim((block) => `
2756
+ throw new ParseError(spaceTrim$2((block) => `
2723
2757
  Unsupported format "${formatName}"
2724
2758
 
2725
2759
  Available formats:
@@ -2731,7 +2765,7 @@ const foreachCommandParser = {
2731
2765
  }
2732
2766
  const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(subformatName));
2733
2767
  if (subvalueParser === undefined) {
2734
- throw new ParseError(spaceTrim((block) => `
2768
+ throw new ParseError(spaceTrim$2((block) => `
2735
2769
  Unsupported subformat name "${subformatName}" for format "${formatName}"
2736
2770
 
2737
2771
  Available subformat names for format "${formatDefinition.formatName}":
@@ -2779,7 +2813,7 @@ const foreachCommandParser = {
2779
2813
  outputSubparameterName = 'newLine';
2780
2814
  }
2781
2815
  else {
2782
- throw new ParseError(spaceTrim(`
2816
+ throw new ParseError(spaceTrim$2(`
2783
2817
  FOREACH ${formatName} ${subformatName} must specify output subparameter
2784
2818
 
2785
2819
  Correct example:
@@ -2855,7 +2889,7 @@ const formatCommandParser = {
2855
2889
  /**
2856
2890
  * Description of the FORMAT command
2857
2891
  */
2858
- description: spaceTrim(`
2892
+ description: spaceTrim$2(`
2859
2893
  Format command describes the desired output of the task (after post-processing)
2860
2894
  It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.
2861
2895
  `),
@@ -3227,7 +3261,7 @@ const formfactorCommandParser = {
3227
3261
  const formfactorNameCandidate = args[0].toUpperCase();
3228
3262
  const formfactor = FORMFACTOR_DEFINITIONS.find((definition) => [definition.name, ...{ aliasNames: [], ...definition }.aliasNames].includes(formfactorNameCandidate));
3229
3263
  if (formfactor === undefined) {
3230
- throw new ParseError(spaceTrim((block) => `
3264
+ throw new ParseError(spaceTrim$2((block) => `
3231
3265
  Unknown formfactor name "${formfactorNameCandidate}"
3232
3266
 
3233
3267
  Available formfactors:
@@ -3246,7 +3280,7 @@ const formfactorCommandParser = {
3246
3280
  */
3247
3281
  $applyToPipelineJson(command, $pipelineJson) {
3248
3282
  if ($pipelineJson.formfactorName !== undefined && $pipelineJson.formfactorName !== command.formfactorName) {
3249
- throw new ParseError(spaceTrim(`
3283
+ throw new ParseError(spaceTrim$2(`
3250
3284
  Redefinition of \`FORMFACTOR\` in the pipeline head
3251
3285
 
3252
3286
  You have used:
@@ -3549,7 +3583,7 @@ const knowledgeCommandParser = {
3549
3583
  */
3550
3584
  parse(input) {
3551
3585
  const { args } = input;
3552
- const knowledgeSourceContent = spaceTrim(args[0] || '');
3586
+ const knowledgeSourceContent = spaceTrim$2(args[0] || '');
3553
3587
  if (knowledgeSourceContent === '') {
3554
3588
  throw new ParseError(`Source is not defined`);
3555
3589
  }
@@ -3643,7 +3677,7 @@ const modelCommandParser = {
3643
3677
  */
3644
3678
  parse(input) {
3645
3679
  const { args, normalized } = input;
3646
- const availableVariantsMessage = spaceTrim((block) => `
3680
+ const availableVariantsMessage = spaceTrim$2((block) => `
3647
3681
  Available variants are:
3648
3682
  ${block(MODEL_VARIANTS.map((variantName) => `- ${variantName}${variantName !== 'EMBEDDING' ? '' : ' (Not available in pipeline)'}`).join('\n'))}
3649
3683
  `);
@@ -3665,14 +3699,14 @@ const modelCommandParser = {
3665
3699
  // <- Note: [🤖]
3666
3700
  }
3667
3701
  else if (normalized.startsWith('MODEL_VARIANT_EMBED')) {
3668
- spaceTrim((block) => `
3702
+ spaceTrim$2((block) => `
3669
3703
  Embedding model can not be used in pipeline
3670
3704
 
3671
3705
  ${block(availableVariantsMessage)}
3672
3706
  `);
3673
3707
  }
3674
3708
  else {
3675
- throw new ParseError(spaceTrim((block) => `
3709
+ throw new ParseError(spaceTrim$2((block) => `
3676
3710
  Unknown model variant in command:
3677
3711
 
3678
3712
  ${block(availableVariantsMessage)}
@@ -3687,7 +3721,7 @@ const modelCommandParser = {
3687
3721
  };
3688
3722
  }
3689
3723
  else {
3690
- throw new ParseError(spaceTrim((block) => `
3724
+ throw new ParseError(spaceTrim$2((block) => `
3691
3725
  Unknown model key in command.
3692
3726
 
3693
3727
  Supported model keys are:
@@ -3714,7 +3748,7 @@ const modelCommandParser = {
3714
3748
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3715
3749
  }
3716
3750
  else {
3717
- throw new ParseError(spaceTrim(`
3751
+ throw new ParseError(spaceTrim$2(`
3718
3752
  Redefinition of \`MODEL ${command.key}\` in the pipeline head
3719
3753
 
3720
3754
  You have used:
@@ -3746,7 +3780,7 @@ const modelCommandParser = {
3746
3780
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3747
3781
  }
3748
3782
  else {
3749
- throw new ParseError(spaceTrim(`
3783
+ throw new ParseError(spaceTrim$2(`
3750
3784
  Redefinition of MODEL \`${command.key}\` in the task "${$taskJson.title || $taskJson.name}"
3751
3785
 
3752
3786
  You have used:
@@ -3756,7 +3790,7 @@ const modelCommandParser = {
3756
3790
  }
3757
3791
  }
3758
3792
  if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
3759
- console.log(spaceTrim(`
3793
+ console.log(spaceTrim$2(`
3760
3794
  Setting MODEL \`${command.key}\` in the task "${$taskJson.title || $taskJson.name}" to the same value as in the pipeline head
3761
3795
 
3762
3796
  In pipeline head:
@@ -3839,7 +3873,7 @@ const parameterCommandParser = {
3839
3873
  // <- TODO: When [🥶] fixed, change to:
3840
3874
  // > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
3841
3875
  if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
3842
- throw new ParseError(spaceTrim((block) => `
3876
+ throw new ParseError(spaceTrim$2((block) => `
3843
3877
  Parameter \`{${parameterNameRaw}}\` can not contain another parameter in description
3844
3878
 
3845
3879
  The description:
@@ -4021,7 +4055,7 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
4021
4055
  persona.description = personaDescription;
4022
4056
  return;
4023
4057
  }
4024
- console.warn(spaceTrim(`
4058
+ console.warn(spaceTrim$2(`
4025
4059
 
4026
4060
  Persona "${personaName}" is defined multiple times with different description:
4027
4061
 
@@ -4032,7 +4066,7 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
4032
4066
  ${personaDescription}
4033
4067
 
4034
4068
  `));
4035
- persona.description += spaceTrim('\n\n' + personaDescription);
4069
+ persona.description += spaceTrim$2('\n\n' + personaDescription);
4036
4070
  }
4037
4071
 
4038
4072
  /**
@@ -4254,7 +4288,7 @@ const sectionCommandParser = {
4254
4288
  normalized = normalized.split('DIALOGUE').join('DIALOG');
4255
4289
  const taskTypes = SectionTypes.filter((sectionType) => normalized.includes(sectionType.split('_TASK').join('')));
4256
4290
  if (taskTypes.length !== 1) {
4257
- throw new ParseError(spaceTrim((block) => `
4291
+ throw new ParseError(spaceTrim$2((block) => `
4258
4292
  Unknown section type "${normalized}"
4259
4293
 
4260
4294
  Supported section types are:
@@ -4274,7 +4308,7 @@ const sectionCommandParser = {
4274
4308
  */
4275
4309
  $applyToTaskJson(command, $taskJson, $pipelineJson) {
4276
4310
  if ($taskJson.isSectionTypeSet === true) {
4277
- throw new ParseError(spaceTrim(`
4311
+ throw new ParseError(spaceTrim$2(`
4278
4312
  Section type is already defined in the section.
4279
4313
  It can be defined only once.
4280
4314
  `));
@@ -4947,7 +4981,7 @@ function removeMarkdownComments(content) {
4947
4981
  */
4948
4982
  function isFlatPipeline(pipelineString) {
4949
4983
  pipelineString = removeMarkdownComments(pipelineString);
4950
- pipelineString = spaceTrim(pipelineString);
4984
+ pipelineString = spaceTrim$2(pipelineString);
4951
4985
  const isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
4952
4986
  //const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
4953
4987
  const isBacktickBlockUsed = pipelineString.includes('```');
@@ -4973,7 +5007,7 @@ function deflatePipeline(pipelineString) {
4973
5007
  if (!isFlatPipeline(pipelineString)) {
4974
5008
  return pipelineString;
4975
5009
  }
4976
- pipelineString = spaceTrim(pipelineString);
5010
+ pipelineString = spaceTrim$2(pipelineString);
4977
5011
  const pipelineStringLines = pipelineString.split('\n');
4978
5012
  const potentialReturnStatement = pipelineStringLines.pop();
4979
5013
  let returnStatement;
@@ -4986,19 +5020,19 @@ function deflatePipeline(pipelineString) {
4986
5020
  returnStatement = `-> {${DEFAULT_BOOK_OUTPUT_PARAMETER_NAME}}`;
4987
5021
  pipelineStringLines.push(potentialReturnStatement);
4988
5022
  }
4989
- const prompt = spaceTrim(pipelineStringLines.join('\n'));
5023
+ const prompt = spaceTrim$2(pipelineStringLines.join('\n'));
4990
5024
  let quotedPrompt;
4991
5025
  if (prompt.split('\n').length <= 1) {
4992
5026
  quotedPrompt = `> ${prompt}`;
4993
5027
  }
4994
5028
  else {
4995
- quotedPrompt = spaceTrim((block) => `
5029
+ quotedPrompt = spaceTrim$2((block) => `
4996
5030
  \`\`\`
4997
5031
  ${block(prompt.split('`').join('\\`'))}
4998
5032
  \`\`\`
4999
5033
  `);
5000
5034
  }
5001
- pipelineString = validatePipelineString(spaceTrim((block) => `
5035
+ pipelineString = validatePipelineString(spaceTrim$2((block) => `
5002
5036
  # ${DEFAULT_BOOK_TITLE}
5003
5037
 
5004
5038
  ## Prompt
@@ -5066,7 +5100,7 @@ function addPipelineCommand(options) {
5066
5100
  );
5067
5101
  */
5068
5102
  }
5069
- return spaceTrim(newLines.join('\n'));
5103
+ return spaceTrim$2(newLines.join('\n'));
5070
5104
  }
5071
5105
  /**
5072
5106
  * TODO: [🧠] What is the better solution - `- xxx`, - `- xxx` or preserve (see also next TODO)
@@ -5108,7 +5142,7 @@ function removePipelineCommand(options) {
5108
5142
  }
5109
5143
  newLines.push(line);
5110
5144
  }
5111
- const newPipeline = spaceTrim(newLines.join('\n'));
5145
+ const newPipeline = spaceTrim$2(newLines.join('\n'));
5112
5146
  return newPipeline;
5113
5147
  }
5114
5148
 
@@ -5211,7 +5245,7 @@ function isSerializableAsJson(value) {
5211
5245
  */
5212
5246
  function stringifyPipelineJson(pipeline) {
5213
5247
  if (!isSerializableAsJson(pipeline)) {
5214
- throw new UnexpectedError(spaceTrim(`
5248
+ throw new UnexpectedError(spaceTrim$2(`
5215
5249
  Cannot stringify the pipeline, because it is not serializable as JSON
5216
5250
 
5217
5251
  There can be multiple reasons: