@promptbook/node 0.103.0-55 → 0.103.0-66

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 (42) hide show
  1. package/esm/index.es.js +137 -85
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/components.index.d.ts +2 -2
  4. package/esm/typings/src/_packages/core.index.d.ts +6 -8
  5. package/esm/typings/src/_packages/types.index.d.ts +7 -1
  6. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +2 -1
  7. package/esm/typings/src/book-2.0/agent-source/createCommitmentRegex.d.ts +1 -1
  8. package/esm/typings/src/book-components/Chat/AgentChat/AgentChat.d.ts +3 -0
  9. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +6 -0
  10. package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +5 -0
  11. package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgentIntegration.d.ts +52 -0
  12. package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgentSeamlessIntegration.d.ts +14 -0
  13. package/esm/typings/src/book-components/icons/SendIcon.d.ts +3 -0
  14. package/esm/typings/src/commitments/CLOSED/CLOSED.d.ts +4 -0
  15. package/esm/typings/src/commitments/CLOSED/CLOSED.test.d.ts +4 -0
  16. package/esm/typings/src/commitments/META_COLOR/META_COLOR.d.ts +6 -0
  17. package/esm/typings/src/commitments/META_FONT/META_FONT.d.ts +42 -0
  18. package/esm/typings/src/commitments/USE/USE.d.ts +53 -0
  19. package/esm/typings/src/commitments/USE_BROWSER/USE_BROWSER.d.ts +42 -0
  20. package/esm/typings/src/commitments/USE_BROWSER/USE_BROWSER.test.d.ts +1 -0
  21. package/esm/typings/src/commitments/{IMPORTANT/IMPORTANT.d.ts → USE_MCP/USE_MCP.d.ts} +16 -5
  22. package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +38 -0
  23. package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +6 -0
  24. package/esm/typings/src/commitments/index.d.ts +93 -1
  25. package/esm/typings/src/llm-providers/agent/Agent.d.ts +3 -1
  26. package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +1 -1
  27. package/esm/typings/src/playground/playground.d.ts +3 -0
  28. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  29. package/esm/typings/src/utils/color/Color.d.ts +9 -1
  30. package/esm/typings/src/utils/color/css-colors.d.ts +1 -0
  31. package/esm/typings/src/utils/random/$generateBookBoilerplate.d.ts +6 -0
  32. package/esm/typings/src/utils/random/CzechNamePool.d.ts +7 -0
  33. package/esm/typings/src/utils/random/EnglishNamePool.d.ts +7 -0
  34. package/esm/typings/src/utils/random/NamePool.d.ts +17 -0
  35. package/esm/typings/src/utils/random/getNamePool.d.ts +10 -0
  36. package/esm/typings/src/version.d.ts +1 -1
  37. package/package.json +3 -3
  38. package/umd/index.umd.js +145 -93
  39. package/umd/index.umd.js.map +1 -1
  40. package/esm/typings/src/book-components/PromptbookAgent/PromptbookAgent.d.ts +0 -29
  41. package/esm/typings/src/commitments/registry.d.ts +0 -68
  42. package/esm/typings/src/playground/playground1.d.ts +0 -2
package/esm/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import colors from 'colors';
2
2
  import { stat, access, constants, readFile, writeFile, readdir, mkdir, watch, unlink } from 'fs/promises';
3
3
  import { basename, join, dirname, isAbsolute, relative } from 'path';
4
- import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
4
+ import spaceTrim$2, { spaceTrim as spaceTrim$1 } from 'spacetrim';
5
5
  import JSZip from 'jszip';
6
6
  import { randomBytes } from 'crypto';
7
7
  import { Subject } from 'rxjs';
@@ -28,12 +28,23 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-55';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-66';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
35
35
  */
36
36
 
37
+ /**
38
+ * Trims string from all 4 sides
39
+ *
40
+ * Note: This is a re-exported function from the `spacetrim` package which is
41
+ * Developed by same author @hejny as this package
42
+ *
43
+ * @public exported from `@promptbook/utils`
44
+ * @see https://github.com/hejny/spacetrim#usage
45
+ */
46
+ const spaceTrim = spaceTrim$1;
47
+
37
48
  /**
38
49
  * @private util of `@promptbook/color`
39
50
  * @de
@@ -82,6 +93,7 @@ function take(initialValue) {
82
93
  * @public exported from `@promptbook/color`
83
94
  */
84
95
  const CSS_COLORS = {
96
+ promptbook: '#79EAFD',
85
97
  transparent: 'rgba(0,0,0,0)',
86
98
  aliceblue: '#f0f8ff',
87
99
  antiquewhite: '#faebd7',
@@ -282,21 +294,61 @@ class Color {
282
294
  * @param color
283
295
  * @returns Color object
284
296
  */
285
- static from(color) {
286
- if (color instanceof Color) {
297
+ static from(color, _isSingleValue = false) {
298
+ if (color === '') {
299
+ throw new Error(`Can not create color from empty string`);
300
+ }
301
+ else if (color instanceof Color) {
287
302
  return take(color);
288
303
  }
289
304
  else if (Color.isColor(color)) {
290
305
  return take(color);
291
306
  }
292
307
  else if (typeof color === 'string') {
293
- return Color.fromString(color);
308
+ try {
309
+ return Color.fromString(color);
310
+ }
311
+ catch (error) {
312
+ // <- Note: Can not use `assertsError(error)` here because it causes circular dependency
313
+ if (_isSingleValue) {
314
+ throw error;
315
+ }
316
+ const parts = color.split(/[\s+,;|]/);
317
+ if (parts.length > 0) {
318
+ return Color.from(parts[0].trim(), true);
319
+ }
320
+ else {
321
+ throw new Error(`Can not create color from given string "${color}"`);
322
+ }
323
+ }
294
324
  }
295
325
  else {
296
326
  console.error({ color });
297
327
  throw new Error(`Can not create color from given object`);
298
328
  }
299
329
  }
330
+ /**
331
+ * Creates a new Color instance from miscellaneous formats
332
+ * It just does not throw error when it fails, it returns PROMPTBOOK_COLOR instead
333
+ *
334
+ * @param color
335
+ * @returns Color object
336
+ */
337
+ static fromSafe(color) {
338
+ try {
339
+ return Color.from(color);
340
+ }
341
+ catch (error) {
342
+ // <- Note: Can not use `assertsError(error)` here because it causes circular dependency
343
+ console.warn(spaceTrim((block) => `
344
+ Color.fromSafe error:
345
+ ${block(error.message)}
346
+
347
+ Returning default PROMPTBOOK_COLOR.
348
+ `));
349
+ return Color.fromString('promptbook');
350
+ }
351
+ }
300
352
  /**
301
353
  * Creates a new Color instance from miscellaneous string formats
302
354
  *
@@ -906,7 +958,7 @@ const ADMIN_GITHUB_NAME = 'hejny';
906
958
  *
907
959
  * @public exported from `@promptbook/core`
908
960
  */
909
- const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
961
+ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
910
962
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
911
963
  /**
912
964
  * Colors for syntax highlighting in the `<BookEditor/>`
@@ -1131,7 +1183,7 @@ true);
1131
1183
  function getErrorReportUrl(error) {
1132
1184
  const report = {
1133
1185
  title: `🐜 Error report from ${NAME}`,
1134
- body: spaceTrim((block) => `
1186
+ body: spaceTrim$2((block) => `
1135
1187
 
1136
1188
 
1137
1189
  \`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
@@ -1204,7 +1256,7 @@ function jsonParse(value) {
1204
1256
  }
1205
1257
  else if (typeof value !== 'string') {
1206
1258
  console.error('Can not parse JSON from non-string value.', { text: value });
1207
- throw new Error(spaceTrim(`
1259
+ throw new Error(spaceTrim$2(`
1208
1260
  Can not parse JSON from non-string value.
1209
1261
 
1210
1262
  The value type: ${typeof value}
@@ -1218,7 +1270,7 @@ function jsonParse(value) {
1218
1270
  if (!(error instanceof Error)) {
1219
1271
  throw error;
1220
1272
  }
1221
- throw new Error(spaceTrim((block) => `
1273
+ throw new Error(spaceTrim$2((block) => `
1222
1274
  ${block(error.message)}
1223
1275
 
1224
1276
  The expected JSON text:
@@ -1367,7 +1419,7 @@ function checkSerializableAsJson(options) {
1367
1419
  }
1368
1420
  else if (typeof value === 'object') {
1369
1421
  if (value instanceof Date) {
1370
- throw new UnexpectedError(spaceTrim((block) => `
1422
+ throw new UnexpectedError(spaceTrim$2((block) => `
1371
1423
  \`${name}\` is Date
1372
1424
 
1373
1425
  Use \`string_date_iso8601\` instead
@@ -1386,7 +1438,7 @@ function checkSerializableAsJson(options) {
1386
1438
  throw new UnexpectedError(`${name} is RegExp`);
1387
1439
  }
1388
1440
  else if (value instanceof Error) {
1389
- throw new UnexpectedError(spaceTrim((block) => `
1441
+ throw new UnexpectedError(spaceTrim$2((block) => `
1390
1442
  \`${name}\` is unserialized Error
1391
1443
 
1392
1444
  Use function \`serializeError\`
@@ -1409,7 +1461,7 @@ function checkSerializableAsJson(options) {
1409
1461
  }
1410
1462
  catch (error) {
1411
1463
  assertsError(error);
1412
- throw new UnexpectedError(spaceTrim((block) => `
1464
+ throw new UnexpectedError(spaceTrim$2((block) => `
1413
1465
  \`${name}\` is not serializable
1414
1466
 
1415
1467
  ${block(error.stack || error.message)}
@@ -1441,7 +1493,7 @@ function checkSerializableAsJson(options) {
1441
1493
  }
1442
1494
  }
1443
1495
  else {
1444
- throw new UnexpectedError(spaceTrim((block) => `
1496
+ throw new UnexpectedError(spaceTrim$2((block) => `
1445
1497
  \`${name}\` is unknown type
1446
1498
 
1447
1499
  Additional message for \`${name}\`:
@@ -2294,7 +2346,7 @@ function pipelineJsonToString(pipelineJson) {
2294
2346
  pipelineString += '\n\n';
2295
2347
  pipelineString += '```' + contentLanguage;
2296
2348
  pipelineString += '\n';
2297
- pipelineString += spaceTrim(content);
2349
+ pipelineString += spaceTrim$2(content);
2298
2350
  // <- TODO: [main] !!3 Escape
2299
2351
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
2300
2352
  pipelineString += '\n';
@@ -2862,7 +2914,7 @@ function serializeError(error) {
2862
2914
  const { name, message, stack } = error;
2863
2915
  const { id } = error;
2864
2916
  if (!Object.keys(ALL_ERRORS).includes(name)) {
2865
- console.error(spaceTrim((block) => `
2917
+ console.error(spaceTrim$2((block) => `
2866
2918
 
2867
2919
  Cannot serialize error with name "${name}"
2868
2920
 
@@ -2926,7 +2978,7 @@ function deserializeError(error) {
2926
2978
  message = `${name}: ${message}`;
2927
2979
  }
2928
2980
  if (stack !== undefined && stack !== '') {
2929
- message = spaceTrim((block) => `
2981
+ message = spaceTrim$2((block) => `
2930
2982
  ${block(message)}
2931
2983
 
2932
2984
  Original stack trace:
@@ -3604,7 +3656,7 @@ const CsvFormatParser = {
3604
3656
  const { value, outputParameterName, settings, mapCallback, onProgress } = options;
3605
3657
  const csv = csvParse(value, settings);
3606
3658
  if (csv.errors.length !== 0) {
3607
- throw new CsvFormatError(spaceTrim((block) => `
3659
+ throw new CsvFormatError(spaceTrim$2((block) => `
3608
3660
  CSV parsing error
3609
3661
 
3610
3662
  Error(s) from CSV parsing:
@@ -3649,7 +3701,7 @@ const CsvFormatParser = {
3649
3701
  const { value, settings, mapCallback, onProgress } = options;
3650
3702
  const csv = csvParse(value, settings);
3651
3703
  if (csv.errors.length !== 0) {
3652
- throw new CsvFormatError(spaceTrim((block) => `
3704
+ throw new CsvFormatError(spaceTrim$2((block) => `
3653
3705
  CSV parsing error
3654
3706
 
3655
3707
  Error(s) from CSV parsing:
@@ -3859,7 +3911,7 @@ function mapAvailableToExpectedParameters(options) {
3859
3911
  }
3860
3912
  // Phase 2️⃣: Non-matching mapping
3861
3913
  if (expectedParameterNames.size !== availableParametersNames.size) {
3862
- throw new PipelineExecutionError(spaceTrim((block) => `
3914
+ throw new PipelineExecutionError(spaceTrim$2((block) => `
3863
3915
  Can not map available parameters to expected parameters
3864
3916
 
3865
3917
  Mapped parameters:
@@ -3937,14 +3989,14 @@ class MultipleLlmExecutionTools {
3937
3989
  if (description === undefined) {
3938
3990
  return headLine;
3939
3991
  }
3940
- return spaceTrim((block) => `
3992
+ return spaceTrim$2((block) => `
3941
3993
  ${headLine}
3942
3994
 
3943
3995
  ${ /* <- Note: Indenting the description: */block(description)}
3944
3996
  `);
3945
3997
  })
3946
3998
  .join('\n\n');
3947
- return spaceTrim((block) => `
3999
+ return spaceTrim$2((block) => `
3948
4000
  Multiple LLM Providers:
3949
4001
 
3950
4002
  ${block(innerModelsTitlesAndDescriptions)}
@@ -4035,7 +4087,7 @@ class MultipleLlmExecutionTools {
4035
4087
  // 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
4036
4088
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
4037
4089
  // 3) ...
4038
- spaceTrim((block) => `
4090
+ spaceTrim$2((block) => `
4039
4091
  All execution tools of ${this.title} failed:
4040
4092
 
4041
4093
  ${block(errors
@@ -4048,7 +4100,7 @@ class MultipleLlmExecutionTools {
4048
4100
  throw new PipelineExecutionError(`You have not provided any \`LlmExecutionTools\` into ${this.title}`);
4049
4101
  }
4050
4102
  else {
4051
- throw new PipelineExecutionError(spaceTrim((block) => `
4103
+ throw new PipelineExecutionError(spaceTrim$2((block) => `
4052
4104
  You have not provided any \`LlmExecutionTools\` that support model variant "${prompt.modelRequirements.modelVariant}" into ${this.title}
4053
4105
 
4054
4106
  Available \`LlmExecutionTools\`:
@@ -4081,7 +4133,7 @@ class MultipleLlmExecutionTools {
4081
4133
  */
4082
4134
  function joinLlmExecutionTools(title, ...llmExecutionTools) {
4083
4135
  if (llmExecutionTools.length === 0) {
4084
- const warningMessage = spaceTrim(`
4136
+ const warningMessage = spaceTrim$2(`
4085
4137
  You have not provided any \`LlmExecutionTools\`
4086
4138
  This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.
4087
4139
 
@@ -5170,7 +5222,7 @@ async function executeFormatSubvalues(options) {
5170
5222
  return /* not await */ executeAttempts({ ...options, logLlmCall });
5171
5223
  }
5172
5224
  if (jokerParameterNames.length !== 0) {
5173
- throw new UnexpectedError(spaceTrim((block) => `
5225
+ throw new UnexpectedError(spaceTrim$2((block) => `
5174
5226
  JOKER parameters are not supported together with FOREACH command
5175
5227
 
5176
5228
  [🧞‍♀️] This should be prevented in \`validatePipeline\`
@@ -5183,7 +5235,7 @@ async function executeFormatSubvalues(options) {
5183
5235
  if (formatDefinition === undefined) {
5184
5236
  throw new UnexpectedError(
5185
5237
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
5186
- spaceTrim((block) => `
5238
+ spaceTrim$2((block) => `
5187
5239
  Unsupported format "${task.foreach.formatName}"
5188
5240
 
5189
5241
  Available formats:
@@ -5200,7 +5252,7 @@ async function executeFormatSubvalues(options) {
5200
5252
  if (subvalueParser === undefined) {
5201
5253
  throw new UnexpectedError(
5202
5254
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
5203
- spaceTrim((block) => `
5255
+ spaceTrim$2((block) => `
5204
5256
  Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
5205
5257
 
5206
5258
  Available subformat names for format "${formatDefinition.formatName}":
@@ -5240,7 +5292,7 @@ async function executeFormatSubvalues(options) {
5240
5292
  if (!(error instanceof PipelineExecutionError)) {
5241
5293
  throw error;
5242
5294
  }
5243
- const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
5295
+ const highLevelError = new PipelineExecutionError(spaceTrim$2((block) => `
5244
5296
  ${error.message}
5245
5297
 
5246
5298
  This is error in FOREACH command when mapping ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
@@ -5264,7 +5316,7 @@ async function executeFormatSubvalues(options) {
5264
5316
  ...options,
5265
5317
  priority: priority + index,
5266
5318
  parameters: allSubparameters,
5267
- pipelineIdentification: spaceTrim((block) => `
5319
+ pipelineIdentification: spaceTrim$2((block) => `
5268
5320
  ${block(pipelineIdentification)}
5269
5321
  Subparameter index: ${index}
5270
5322
  `),
@@ -5273,7 +5325,7 @@ async function executeFormatSubvalues(options) {
5273
5325
  }
5274
5326
  catch (error) {
5275
5327
  if (length > BIG_DATASET_TRESHOLD) {
5276
- console.error(spaceTrim((block) => `
5328
+ console.error(spaceTrim$2((block) => `
5277
5329
  ${error.message}
5278
5330
 
5279
5331
  This is error in FOREACH command when processing ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
@@ -6416,14 +6468,14 @@ function $registeredScrapersMessage(availableScrapers) {
6416
6468
  return { ...metadata, isMetadataAviailable, isInstalled, isAvailableInTools };
6417
6469
  });
6418
6470
  if (metadata.length === 0) {
6419
- return spaceTrim(`
6471
+ return spaceTrim$2(`
6420
6472
  **No scrapers are available**
6421
6473
 
6422
6474
  This is a unexpected behavior, you are probably using some broken version of Promptbook
6423
6475
  At least there should be available the metadata of the scrapers
6424
6476
  `);
6425
6477
  }
6426
- return spaceTrim((block) => `
6478
+ return spaceTrim$2((block) => `
6427
6479
  Available scrapers are:
6428
6480
  ${block(metadata
6429
6481
  .map(({ packageName, className, isMetadataAviailable, isInstalled, mimeTypes, isAvailableInBrowser, isAvailableInTools, }, i) => {
@@ -6666,7 +6718,7 @@ const promptbookFetch = async (urlOrRequest, init) => {
6666
6718
  else if (urlOrRequest instanceof Request) {
6667
6719
  url = urlOrRequest.url;
6668
6720
  }
6669
- throw new PromptbookFetchError(spaceTrim((block) => `
6721
+ throw new PromptbookFetchError(spaceTrim$2((block) => `
6670
6722
  Can not fetch "${url}"
6671
6723
 
6672
6724
  Fetch error:
@@ -6827,7 +6879,7 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
6827
6879
  const fileExtension = getFileExtension(filename);
6828
6880
  const mimeType = extensionToMimeType(fileExtension || '');
6829
6881
  if (!(await isFileExisting(filename, tools.fs))) {
6830
- throw new NotFoundError(spaceTrim((block) => `
6882
+ throw new NotFoundError(spaceTrim$2((block) => `
6831
6883
  Can not make source handler for file which does not exist:
6832
6884
 
6833
6885
  File:
@@ -6920,7 +6972,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
6920
6972
  // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
6921
6973
  break;
6922
6974
  }
6923
- console.warn(spaceTrim((block) => `
6975
+ console.warn(spaceTrim$2((block) => `
6924
6976
  Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
6925
6977
 
6926
6978
  The source:
@@ -6936,7 +6988,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
6936
6988
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
6937
6989
  }
6938
6990
  if (partialPieces === null) {
6939
- throw new KnowledgeScrapeError(spaceTrim((block) => `
6991
+ throw new KnowledgeScrapeError(spaceTrim$2((block) => `
6940
6992
  Cannot scrape knowledge
6941
6993
 
6942
6994
  The source:
@@ -7272,7 +7324,7 @@ const knowledgeCommandParser = {
7272
7324
  */
7273
7325
  parse(input) {
7274
7326
  const { args } = input;
7275
- const knowledgeSourceContent = spaceTrim(args[0] || '');
7327
+ const knowledgeSourceContent = spaceTrim$2(args[0] || '');
7276
7328
  if (knowledgeSourceContent === '') {
7277
7329
  throw new ParseError(`Source is not defined`);
7278
7330
  }
@@ -7416,7 +7468,7 @@ const sectionCommandParser = {
7416
7468
  normalized = normalized.split('DIALOGUE').join('DIALOG');
7417
7469
  const taskTypes = SectionTypes.filter((sectionType) => normalized.includes(sectionType.split('_TASK').join('')));
7418
7470
  if (taskTypes.length !== 1) {
7419
- throw new ParseError(spaceTrim((block) => `
7471
+ throw new ParseError(spaceTrim$2((block) => `
7420
7472
  Unknown section type "${normalized}"
7421
7473
 
7422
7474
  Supported section types are:
@@ -7436,7 +7488,7 @@ const sectionCommandParser = {
7436
7488
  */
7437
7489
  $applyToTaskJson(command, $taskJson, $pipelineJson) {
7438
7490
  if ($taskJson.isSectionTypeSet === true) {
7439
- throw new ParseError(spaceTrim(`
7491
+ throw new ParseError(spaceTrim$2(`
7440
7492
  Section type is already defined in the section.
7441
7493
  It can be defined only once.
7442
7494
  `));
@@ -7785,7 +7837,7 @@ const expectCommandParser = {
7785
7837
  /**
7786
7838
  * Description of the FORMAT command
7787
7839
  */
7788
- description: spaceTrim(`
7840
+ description: spaceTrim$2(`
7789
7841
  Expect command describes the desired output of the task *(after post-processing)*
7790
7842
  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.
7791
7843
  `),
@@ -7859,7 +7911,7 @@ const expectCommandParser = {
7859
7911
  }
7860
7912
  catch (error) {
7861
7913
  assertsError(error);
7862
- throw new ParseError(spaceTrim((block) => `
7914
+ throw new ParseError(spaceTrim$2((block) => `
7863
7915
  Invalid FORMAT command
7864
7916
  ${block(error.message)}:
7865
7917
  `));
@@ -8049,7 +8101,7 @@ function validateParameterName(parameterName) {
8049
8101
  if (!(error instanceof ParseError)) {
8050
8102
  throw error;
8051
8103
  }
8052
- throw new ParseError(spaceTrim((block) => `
8104
+ throw new ParseError(spaceTrim$2((block) => `
8053
8105
  ${block(error.message)}
8054
8106
 
8055
8107
  Tried to validate parameter name:
@@ -8108,7 +8160,7 @@ const foreachCommandParser = {
8108
8160
  const assignSign = args[3];
8109
8161
  const formatDefinition = FORMAT_DEFINITIONS.find((formatDefinition) => [formatDefinition.formatName, ...(formatDefinition.aliases || [])].includes(formatName));
8110
8162
  if (formatDefinition === undefined) {
8111
- throw new ParseError(spaceTrim((block) => `
8163
+ throw new ParseError(spaceTrim$2((block) => `
8112
8164
  Unsupported format "${formatName}"
8113
8165
 
8114
8166
  Available formats:
@@ -8120,7 +8172,7 @@ const foreachCommandParser = {
8120
8172
  }
8121
8173
  const subvalueParser = formatDefinition.subvalueParsers.find((subvalueParser) => [subvalueParser.subvalueName, ...(subvalueParser.aliases || [])].includes(subformatName));
8122
8174
  if (subvalueParser === undefined) {
8123
- throw new ParseError(spaceTrim((block) => `
8175
+ throw new ParseError(spaceTrim$2((block) => `
8124
8176
  Unsupported subformat name "${subformatName}" for format "${formatName}"
8125
8177
 
8126
8178
  Available subformat names for format "${formatDefinition.formatName}":
@@ -8168,7 +8220,7 @@ const foreachCommandParser = {
8168
8220
  outputSubparameterName = 'newLine';
8169
8221
  }
8170
8222
  else {
8171
- throw new ParseError(spaceTrim(`
8223
+ throw new ParseError(spaceTrim$2(`
8172
8224
  FOREACH ${formatName} ${subformatName} must specify output subparameter
8173
8225
 
8174
8226
  Correct example:
@@ -8244,7 +8296,7 @@ const formatCommandParser = {
8244
8296
  /**
8245
8297
  * Description of the FORMAT command
8246
8298
  */
8247
- description: spaceTrim(`
8299
+ description: spaceTrim$2(`
8248
8300
  Format command describes the desired output of the task (after post-processing)
8249
8301
  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.
8250
8302
  `),
@@ -8616,7 +8668,7 @@ const formfactorCommandParser = {
8616
8668
  const formfactorNameCandidate = args[0].toUpperCase();
8617
8669
  const formfactor = FORMFACTOR_DEFINITIONS.find((definition) => [definition.name, ...{ aliasNames: [], ...definition }.aliasNames].includes(formfactorNameCandidate));
8618
8670
  if (formfactor === undefined) {
8619
- throw new ParseError(spaceTrim((block) => `
8671
+ throw new ParseError(spaceTrim$2((block) => `
8620
8672
  Unknown formfactor name "${formfactorNameCandidate}"
8621
8673
 
8622
8674
  Available formfactors:
@@ -8635,7 +8687,7 @@ const formfactorCommandParser = {
8635
8687
  */
8636
8688
  $applyToPipelineJson(command, $pipelineJson) {
8637
8689
  if ($pipelineJson.formfactorName !== undefined && $pipelineJson.formfactorName !== command.formfactorName) {
8638
- throw new ParseError(spaceTrim(`
8690
+ throw new ParseError(spaceTrim$2(`
8639
8691
  Redefinition of \`FORMFACTOR\` in the pipeline head
8640
8692
 
8641
8693
  You have used:
@@ -8778,7 +8830,7 @@ const modelCommandParser = {
8778
8830
  */
8779
8831
  parse(input) {
8780
8832
  const { args, normalized } = input;
8781
- const availableVariantsMessage = spaceTrim((block) => `
8833
+ const availableVariantsMessage = spaceTrim$2((block) => `
8782
8834
  Available variants are:
8783
8835
  ${block(MODEL_VARIANTS.map((variantName) => `- ${variantName}${variantName !== 'EMBEDDING' ? '' : ' (Not available in pipeline)'}`).join('\n'))}
8784
8836
  `);
@@ -8800,14 +8852,14 @@ const modelCommandParser = {
8800
8852
  // <- Note: [🤖]
8801
8853
  }
8802
8854
  else if (normalized.startsWith('MODEL_VARIANT_EMBED')) {
8803
- spaceTrim((block) => `
8855
+ spaceTrim$2((block) => `
8804
8856
  Embedding model can not be used in pipeline
8805
8857
 
8806
8858
  ${block(availableVariantsMessage)}
8807
8859
  `);
8808
8860
  }
8809
8861
  else {
8810
- throw new ParseError(spaceTrim((block) => `
8862
+ throw new ParseError(spaceTrim$2((block) => `
8811
8863
  Unknown model variant in command:
8812
8864
 
8813
8865
  ${block(availableVariantsMessage)}
@@ -8822,7 +8874,7 @@ const modelCommandParser = {
8822
8874
  };
8823
8875
  }
8824
8876
  else {
8825
- throw new ParseError(spaceTrim((block) => `
8877
+ throw new ParseError(spaceTrim$2((block) => `
8826
8878
  Unknown model key in command.
8827
8879
 
8828
8880
  Supported model keys are:
@@ -8849,7 +8901,7 @@ const modelCommandParser = {
8849
8901
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
8850
8902
  }
8851
8903
  else {
8852
- throw new ParseError(spaceTrim(`
8904
+ throw new ParseError(spaceTrim$2(`
8853
8905
  Redefinition of \`MODEL ${command.key}\` in the pipeline head
8854
8906
 
8855
8907
  You have used:
@@ -8881,7 +8933,7 @@ const modelCommandParser = {
8881
8933
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
8882
8934
  }
8883
8935
  else {
8884
- throw new ParseError(spaceTrim(`
8936
+ throw new ParseError(spaceTrim$2(`
8885
8937
  Redefinition of MODEL \`${command.key}\` in the task "${$taskJson.title || $taskJson.name}"
8886
8938
 
8887
8939
  You have used:
@@ -8891,7 +8943,7 @@ const modelCommandParser = {
8891
8943
  }
8892
8944
  }
8893
8945
  if (command.value === ($pipelineJson.defaultModelRequirements || {})[command.key]) {
8894
- console.log(spaceTrim(`
8946
+ console.log(spaceTrim$2(`
8895
8947
  Setting MODEL \`${command.key}\` in the task "${$taskJson.title || $taskJson.name}" to the same value as in the pipeline head
8896
8948
 
8897
8949
  In pipeline head:
@@ -8974,7 +9026,7 @@ const parameterCommandParser = {
8974
9026
  // <- TODO: When [🥶] fixed, change to:
8975
9027
  // > const parameterDescriptionRaw = rawArgs.split(parameterNameRaw).join('').trim();
8976
9028
  if (parameterDescriptionRaw && parameterDescriptionRaw.match(/\{(?<embeddedParameterName>[a-z0-9_]+)\}/im)) {
8977
- throw new ParseError(spaceTrim((block) => `
9029
+ throw new ParseError(spaceTrim$2((block) => `
8978
9030
  Parameter \`{${parameterNameRaw}}\` can not contain another parameter in description
8979
9031
 
8980
9032
  The description:
@@ -9156,7 +9208,7 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
9156
9208
  persona.description = personaDescription;
9157
9209
  return;
9158
9210
  }
9159
- console.warn(spaceTrim(`
9211
+ console.warn(spaceTrim$2(`
9160
9212
 
9161
9213
  Persona "${personaName}" is defined multiple times with different description:
9162
9214
 
@@ -9167,7 +9219,7 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
9167
9219
  ${personaDescription}
9168
9220
 
9169
9221
  `));
9170
- persona.description += spaceTrim('\n\n' + personaDescription);
9222
+ persona.description += spaceTrim$2('\n\n' + personaDescription);
9171
9223
  }
9172
9224
 
9173
9225
  /**
@@ -10022,7 +10074,7 @@ function removeMarkdownComments(content) {
10022
10074
  */
10023
10075
  function isFlatPipeline(pipelineString) {
10024
10076
  pipelineString = removeMarkdownComments(pipelineString);
10025
- pipelineString = spaceTrim(pipelineString);
10077
+ pipelineString = spaceTrim$2(pipelineString);
10026
10078
  const isMarkdownBeginningWithHeadline = pipelineString.startsWith('# ');
10027
10079
  //const isLastLineReturnStatement = pipelineString.split('\n').pop()!.split('`').join('').startsWith('->');
10028
10080
  const isBacktickBlockUsed = pipelineString.includes('```');
@@ -10048,7 +10100,7 @@ function deflatePipeline(pipelineString) {
10048
10100
  if (!isFlatPipeline(pipelineString)) {
10049
10101
  return pipelineString;
10050
10102
  }
10051
- pipelineString = spaceTrim(pipelineString);
10103
+ pipelineString = spaceTrim$2(pipelineString);
10052
10104
  const pipelineStringLines = pipelineString.split('\n');
10053
10105
  const potentialReturnStatement = pipelineStringLines.pop();
10054
10106
  let returnStatement;
@@ -10061,19 +10113,19 @@ function deflatePipeline(pipelineString) {
10061
10113
  returnStatement = `-> {${DEFAULT_BOOK_OUTPUT_PARAMETER_NAME}}`;
10062
10114
  pipelineStringLines.push(potentialReturnStatement);
10063
10115
  }
10064
- const prompt = spaceTrim(pipelineStringLines.join('\n'));
10116
+ const prompt = spaceTrim$2(pipelineStringLines.join('\n'));
10065
10117
  let quotedPrompt;
10066
10118
  if (prompt.split('\n').length <= 1) {
10067
10119
  quotedPrompt = `> ${prompt}`;
10068
10120
  }
10069
10121
  else {
10070
- quotedPrompt = spaceTrim((block) => `
10122
+ quotedPrompt = spaceTrim$2((block) => `
10071
10123
  \`\`\`
10072
10124
  ${block(prompt.split('`').join('\\`'))}
10073
10125
  \`\`\`
10074
10126
  `);
10075
10127
  }
10076
- pipelineString = validatePipelineString(spaceTrim((block) => `
10128
+ pipelineString = validatePipelineString(spaceTrim$2((block) => `
10077
10129
  # ${DEFAULT_BOOK_TITLE}
10078
10130
 
10079
10131
  ## Prompt
@@ -10137,7 +10189,7 @@ function extractAllListItemsFromMarkdown(markdown) {
10137
10189
  function extractOneBlockFromMarkdown(markdown) {
10138
10190
  const codeBlocks = extractAllBlocksFromMarkdown(markdown);
10139
10191
  if (codeBlocks.length !== 1) {
10140
- throw new ParseError(spaceTrim((block) => `
10192
+ throw new ParseError(spaceTrim$2((block) => `
10141
10193
  There should be exactly 1 code block in task section, found ${codeBlocks.length} code blocks
10142
10194
 
10143
10195
  ${block(codeBlocks.map((block, i) => `Block ${i + 1}:\n${block.content}`).join('\n\n\n'))}
@@ -10162,7 +10214,7 @@ function parseMarkdownSection(value) {
10162
10214
  }
10163
10215
  const title = lines[0].replace(/^#+\s*/, '');
10164
10216
  const level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
10165
- const content = spaceTrim(lines.slice(1).join('\n'));
10217
+ const content = spaceTrim$2(lines.slice(1).join('\n'));
10166
10218
  if (level < 1 || level > 6) {
10167
10219
  throw new ParseError('Markdown section must have heading level between 1 and 6');
10168
10220
  }
@@ -10190,7 +10242,7 @@ function splitMarkdownIntoSections(markdown) {
10190
10242
  if (buffer.length === 0) {
10191
10243
  return;
10192
10244
  }
10193
- let section = spaceTrim(buffer.join('\n'));
10245
+ let section = spaceTrim$2(buffer.join('\n'));
10194
10246
  if (section === '') {
10195
10247
  return;
10196
10248
  }
@@ -10265,7 +10317,7 @@ function flattenMarkdown(markdown) {
10265
10317
  flattenedMarkdown += `## ${title}` + `\n\n`;
10266
10318
  flattenedMarkdown += content + `\n\n`; // <- [🧠] Maybe 3 new lines?
10267
10319
  }
10268
- return spaceTrim(flattenedMarkdown);
10320
+ return spaceTrim$2(flattenedMarkdown);
10269
10321
  }
10270
10322
  /**
10271
10323
  * TODO: [🏛] This can be part of markdown builder
@@ -11270,13 +11322,13 @@ function $registeredLlmToolsMessage() {
11270
11322
  });
11271
11323
  const usedEnvMessage = $usedEnvFilename === null ? `Unknown \`.env\` file` : `Used \`.env\` file:\n${$usedEnvFilename}`;
11272
11324
  if (metadata.length === 0) {
11273
- return spaceTrim((block) => `
11325
+ return spaceTrim$2((block) => `
11274
11326
  No LLM providers are available.
11275
11327
 
11276
11328
  ${block(usedEnvMessage)}
11277
11329
  `);
11278
11330
  }
11279
- return spaceTrim((block) => `
11331
+ return spaceTrim$2((block) => `
11280
11332
 
11281
11333
  ${block(usedEnvMessage)}
11282
11334
 
@@ -11322,7 +11374,7 @@ function $registeredLlmToolsMessage() {
11322
11374
  morePieces.push(`Not configured`); // <- Note: Can not be configured via environment variables
11323
11375
  }
11324
11376
  }
11325
- let providerMessage = spaceTrim(`
11377
+ let providerMessage = spaceTrim$2(`
11326
11378
  ${i + 1}) **${title}** \`${className}\` from \`${packageName}\`
11327
11379
  ${morePieces.join('; ')}
11328
11380
  `);
@@ -11484,7 +11536,7 @@ function createLlmToolsFromConfiguration(configuration, options = {}) {
11484
11536
  .find(({ packageName, className }) => llmConfiguration.packageName === packageName && llmConfiguration.className === className);
11485
11537
  if (registeredItem === undefined) {
11486
11538
  // console.log('$llmToolsRegister.list()', $llmToolsRegister.list());
11487
- throw new Error(spaceTrim((block) => `
11539
+ throw new Error(spaceTrim$2((block) => `
11488
11540
  There is no constructor for LLM provider \`${llmConfiguration.className}\` from \`${llmConfiguration.packageName}\`
11489
11541
  Running in ${!$isRunningInBrowser() ? '' : 'browser environment'}${!$isRunningInNode() ? '' : 'node environment'}${!$isRunningInWebWorker() ? '' : 'worker environment'}
11490
11542
 
@@ -11552,14 +11604,14 @@ async function $provideLlmToolsFromEnv(options = {}) {
11552
11604
  const configuration = await $provideLlmToolsConfigurationFromEnv();
11553
11605
  if (configuration.length === 0) {
11554
11606
  if ($llmToolsMetadataRegister.list().length === 0) {
11555
- throw new UnexpectedError(spaceTrim((block) => `
11607
+ throw new UnexpectedError(spaceTrim$2((block) => `
11556
11608
  No LLM tools registered, this is probably a bug in the Promptbook library
11557
11609
 
11558
11610
  ${block($registeredLlmToolsMessage())}}
11559
11611
  `));
11560
11612
  }
11561
11613
  // TODO: [🥃]
11562
- throw new Error(spaceTrim((block) => `
11614
+ throw new Error(spaceTrim$2((block) => `
11563
11615
  No LLM tools found in the environment
11564
11616
 
11565
11617
  ${block($registeredLlmToolsMessage())}}
@@ -11917,8 +11969,8 @@ class JavascriptEvalExecutionTools {
11917
11969
  }
11918
11970
  // Note: [💎]
11919
11971
  // Note: Using direct eval, following variables are in same scope as eval call so they are accessible from inside the evaluated script:
11920
- const spaceTrim$1 = (_) => spaceTrim(_);
11921
- $preserve(spaceTrim$1);
11972
+ const spaceTrim = (_) => spaceTrim$2(_);
11973
+ $preserve(spaceTrim);
11922
11974
  const removeQuotes$1 = removeQuotes;
11923
11975
  $preserve(removeQuotes$1);
11924
11976
  const unwrapResult$1 = unwrapResult;
@@ -11971,7 +12023,7 @@ class JavascriptEvalExecutionTools {
11971
12023
  // TODO: DRY [🍯]
11972
12024
  const buildinFunctions = {
11973
12025
  // TODO: [🍯] DRY all these functions across the file
11974
- spaceTrim: spaceTrim$1,
12026
+ spaceTrim,
11975
12027
  removeQuotes: removeQuotes$1,
11976
12028
  unwrapResult: unwrapResult$1,
11977
12029
  trimEndOfCodeBlock: trimEndOfCodeBlock$1,
@@ -12008,7 +12060,7 @@ class JavascriptEvalExecutionTools {
12008
12060
  .join('\n');
12009
12061
  // script = templateParameters(script, parameters);
12010
12062
  // <- TODO: [🧠][🥳] Should be this is one of two variants how to use parameters in script
12011
- const statementToEvaluate = spaceTrim((block) => `
12063
+ const statementToEvaluate = spaceTrim$2((block) => `
12012
12064
 
12013
12065
  // Build-in functions:
12014
12066
  ${block(buildinFunctionsStatement)}
@@ -12023,7 +12075,7 @@ class JavascriptEvalExecutionTools {
12023
12075
  (()=>{ ${script} })()
12024
12076
  `);
12025
12077
  if (this.options.isVerbose) {
12026
- console.info(spaceTrim((block) => `
12078
+ console.info(spaceTrim$2((block) => `
12027
12079
  🚀 Evaluating ${scriptLanguage} script:
12028
12080
 
12029
12081
  ${block(statementToEvaluate)}`));
@@ -12045,7 +12097,7 @@ class JavascriptEvalExecutionTools {
12045
12097
  To: [PipelineExecutionError: Parameter `{thing}` is not defined],
12046
12098
  */
12047
12099
  if (!statementToEvaluate.includes(undefinedName + '(')) {
12048
- throw new PipelineExecutionError(spaceTrim((block) => `
12100
+ throw new PipelineExecutionError(spaceTrim$2((block) => `
12049
12101
 
12050
12102
  Parameter \`{${undefinedName}}\` is not defined
12051
12103
 
@@ -12067,7 +12119,7 @@ class JavascriptEvalExecutionTools {
12067
12119
  `));
12068
12120
  }
12069
12121
  else {
12070
- throw new PipelineExecutionError(spaceTrim((block) => `
12122
+ throw new PipelineExecutionError(spaceTrim$2((block) => `
12071
12123
  Function ${undefinedName}() is not defined
12072
12124
 
12073
12125
  - Make sure that the function is one of built-in functions
@@ -12314,7 +12366,7 @@ async function createPipelineCollectionFromDirectory(rootPath, tools, options) {
12314
12366
  catch (error) {
12315
12367
  assertsError(error);
12316
12368
  // TODO: [7] DRY
12317
- const wrappedErrorMessage = spaceTrim((block) => `
12369
+ const wrappedErrorMessage = spaceTrim$2((block) => `
12318
12370
  ${error.name} in pipeline ${fileName.split('\\').join('/')}⁠:
12319
12371
 
12320
12372
  Original error message:
@@ -12349,7 +12401,7 @@ async function createPipelineCollectionFromDirectory(rootPath, tools, options) {
12349
12401
  pipeline = { ...pipeline, pipelineUrl };
12350
12402
  }
12351
12403
  else if (!pipeline.pipelineUrl.startsWith(rootUrl)) {
12352
- throw new PipelineUrlError(spaceTrim(`
12404
+ throw new PipelineUrlError(spaceTrim$2(`
12353
12405
  Pipeline with URL ${pipeline.pipelineUrl} is not a child of the root URL ${rootUrl} 🍏
12354
12406
 
12355
12407
  File:
@@ -12387,7 +12439,7 @@ async function createPipelineCollectionFromDirectory(rootPath, tools, options) {
12387
12439
  }
12388
12440
  else {
12389
12441
  const existing = collection.get(pipeline.pipelineUrl);
12390
- throw new PipelineUrlError(spaceTrim(`
12442
+ throw new PipelineUrlError(spaceTrim$2(`
12391
12443
  Pipeline with URL ${pipeline.pipelineUrl} is already in the collection 🍏
12392
12444
 
12393
12445
  Conflicting files:
@@ -12405,7 +12457,7 @@ async function createPipelineCollectionFromDirectory(rootPath, tools, options) {
12405
12457
  catch (error) {
12406
12458
  assertsError(error);
12407
12459
  // TODO: [7] DRY
12408
- const wrappedErrorMessage = spaceTrim((block) => `
12460
+ const wrappedErrorMessage = spaceTrim$2((block) => `
12409
12461
  ${error.name} in pipeline ${fileName.split('\\').join('/')}⁠:
12410
12462
 
12411
12463
  Original error message:
@@ -12462,7 +12514,7 @@ async function $provideScriptingForNode(options) {
12462
12514
  */
12463
12515
  function stringifyPipelineJson(pipeline) {
12464
12516
  if (!isSerializableAsJson(pipeline)) {
12465
- throw new UnexpectedError(spaceTrim(`
12517
+ throw new UnexpectedError(spaceTrim$2(`
12466
12518
  Cannot stringify the pipeline, because it is not serializable as JSON
12467
12519
 
12468
12520
  There can be multiple reasons: