@promptbook/pdf 0.103.0-55 → 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,5 +1,5 @@
1
1
  import { mkdir, rm, readFile } from 'fs/promises';
2
- import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
+ import spaceTrim$2, { spaceTrim as spaceTrim$1 } from 'spacetrim';
3
3
  import { SHA256 } from 'crypto-js';
4
4
  import hexEncoder from 'crypto-js/enc-hex';
5
5
  import { basename, join, dirname, isAbsolute } from 'path';
@@ -24,7 +24,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
24
24
  * @generated
25
25
  * @see https://github.com/webgptorg/promptbook
26
26
  */
27
- const PROMPTBOOK_ENGINE_VERSION = '0.103.0-55';
27
+ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-56';
28
28
  /**
29
29
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
30
30
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -47,6 +47,17 @@ const PROMPTBOOK_ENGINE_VERSION = '0.103.0-55';
47
47
  function keepUnused(...valuesToKeep) {
48
48
  }
49
49
 
50
+ /**
51
+ * Trims string from all 4 sides
52
+ *
53
+ * Note: This is a re-exported function from the `spacetrim` package which is
54
+ * Developed by same author @hejny as this package
55
+ *
56
+ * @public exported from `@promptbook/utils`
57
+ * @see https://github.com/hejny/spacetrim#usage
58
+ */
59
+ const spaceTrim = spaceTrim$1;
60
+
50
61
  /**
51
62
  * Just marks a place of place where should be something implemented
52
63
  * No side effects.
@@ -108,6 +119,7 @@ function take(initialValue) {
108
119
  * @public exported from `@promptbook/color`
109
120
  */
110
121
  const CSS_COLORS = {
122
+ promptbook: '#79EAFD',
111
123
  transparent: 'rgba(0,0,0,0)',
112
124
  aliceblue: '#f0f8ff',
113
125
  antiquewhite: '#faebd7',
@@ -323,6 +335,28 @@ class Color {
323
335
  throw new Error(`Can not create color from given object`);
324
336
  }
325
337
  }
338
+ /**
339
+ * Creates a new Color instance from miscellaneous formats
340
+ * It just does not throw error when it fails, it returns PROMPTBOOK_COLOR instead
341
+ *
342
+ * @param color
343
+ * @returns Color object
344
+ */
345
+ static fromSafe(color) {
346
+ try {
347
+ return Color.from(color);
348
+ }
349
+ catch (error) {
350
+ // <- Note: Can not use `assertsError(error)` here because it causes circular dependency
351
+ console.warn(spaceTrim((block) => `
352
+ Color.fromSafe error:
353
+ ${block(error.message)}
354
+
355
+ Returning default PROMPTBOOK_COLOR.
356
+ `));
357
+ return Color.fromString('promptbook');
358
+ }
359
+ }
326
360
  /**
327
361
  * Creates a new Color instance from miscellaneous string formats
328
362
  *
@@ -932,7 +966,7 @@ const ADMIN_GITHUB_NAME = 'hejny';
932
966
  *
933
967
  * @public exported from `@promptbook/core`
934
968
  */
935
- const PROMPTBOOK_COLOR = Color.fromHex('#79EAFD');
969
+ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
936
970
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
937
971
  /**
938
972
  * Colors for syntax highlighting in the `<BookEditor/>`
@@ -1156,7 +1190,7 @@ class KnowledgeScrapeError extends Error {
1156
1190
  function getErrorReportUrl(error) {
1157
1191
  const report = {
1158
1192
  title: `🐜 Error report from ${NAME}`,
1159
- body: spaceTrim((block) => `
1193
+ body: spaceTrim$2((block) => `
1160
1194
 
1161
1195
 
1162
1196
  \`${error.name || 'Error'}\` has occurred in the [${NAME}], please look into it @${ADMIN_GITHUB_NAME}.
@@ -2053,7 +2087,7 @@ function pipelineJsonToString(pipelineJson) {
2053
2087
  pipelineString += '\n\n';
2054
2088
  pipelineString += '```' + contentLanguage;
2055
2089
  pipelineString += '\n';
2056
- pipelineString += spaceTrim(content);
2090
+ pipelineString += spaceTrim$2(content);
2057
2091
  // <- TODO: [main] !!3 Escape
2058
2092
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
2059
2093
  pipelineString += '\n';
@@ -2174,7 +2208,7 @@ function checkSerializableAsJson(options) {
2174
2208
  }
2175
2209
  else if (typeof value === 'object') {
2176
2210
  if (value instanceof Date) {
2177
- throw new UnexpectedError(spaceTrim((block) => `
2211
+ throw new UnexpectedError(spaceTrim$2((block) => `
2178
2212
  \`${name}\` is Date
2179
2213
 
2180
2214
  Use \`string_date_iso8601\` instead
@@ -2193,7 +2227,7 @@ function checkSerializableAsJson(options) {
2193
2227
  throw new UnexpectedError(`${name} is RegExp`);
2194
2228
  }
2195
2229
  else if (value instanceof Error) {
2196
- throw new UnexpectedError(spaceTrim((block) => `
2230
+ throw new UnexpectedError(spaceTrim$2((block) => `
2197
2231
  \`${name}\` is unserialized Error
2198
2232
 
2199
2233
  Use function \`serializeError\`
@@ -2216,7 +2250,7 @@ function checkSerializableAsJson(options) {
2216
2250
  }
2217
2251
  catch (error) {
2218
2252
  assertsError(error);
2219
- throw new UnexpectedError(spaceTrim((block) => `
2253
+ throw new UnexpectedError(spaceTrim$2((block) => `
2220
2254
  \`${name}\` is not serializable
2221
2255
 
2222
2256
  ${block(error.stack || error.message)}
@@ -2248,7 +2282,7 @@ function checkSerializableAsJson(options) {
2248
2282
  }
2249
2283
  }
2250
2284
  else {
2251
- throw new UnexpectedError(spaceTrim((block) => `
2285
+ throw new UnexpectedError(spaceTrim$2((block) => `
2252
2286
  \`${name}\` is unknown type
2253
2287
 
2254
2288
  Additional message for \`${name}\`:
@@ -3279,7 +3313,7 @@ function serializeError(error) {
3279
3313
  const { name, message, stack } = error;
3280
3314
  const { id } = error;
3281
3315
  if (!Object.keys(ALL_ERRORS).includes(name)) {
3282
- console.error(spaceTrim((block) => `
3316
+ console.error(spaceTrim$2((block) => `
3283
3317
 
3284
3318
  Cannot serialize error with name "${name}"
3285
3319
 
@@ -3312,7 +3346,7 @@ function jsonParse(value) {
3312
3346
  }
3313
3347
  else if (typeof value !== 'string') {
3314
3348
  console.error('Can not parse JSON from non-string value.', { text: value });
3315
- throw new Error(spaceTrim(`
3349
+ throw new Error(spaceTrim$2(`
3316
3350
  Can not parse JSON from non-string value.
3317
3351
 
3318
3352
  The value type: ${typeof value}
@@ -3326,7 +3360,7 @@ function jsonParse(value) {
3326
3360
  if (!(error instanceof Error)) {
3327
3361
  throw error;
3328
3362
  }
3329
- throw new Error(spaceTrim((block) => `
3363
+ throw new Error(spaceTrim$2((block) => `
3330
3364
  ${block(error.message)}
3331
3365
 
3332
3366
  The expected JSON text:
@@ -3379,7 +3413,7 @@ function deserializeError(error) {
3379
3413
  message = `${name}: ${message}`;
3380
3414
  }
3381
3415
  if (stack !== undefined && stack !== '') {
3382
- message = spaceTrim((block) => `
3416
+ message = spaceTrim$2((block) => `
3383
3417
  ${block(message)}
3384
3418
 
3385
3419
  Original stack trace:
@@ -3891,14 +3925,14 @@ class MultipleLlmExecutionTools {
3891
3925
  if (description === undefined) {
3892
3926
  return headLine;
3893
3927
  }
3894
- return spaceTrim((block) => `
3928
+ return spaceTrim$2((block) => `
3895
3929
  ${headLine}
3896
3930
 
3897
3931
  ${ /* <- Note: Indenting the description: */block(description)}
3898
3932
  `);
3899
3933
  })
3900
3934
  .join('\n\n');
3901
- return spaceTrim((block) => `
3935
+ return spaceTrim$2((block) => `
3902
3936
  Multiple LLM Providers:
3903
3937
 
3904
3938
  ${block(innerModelsTitlesAndDescriptions)}
@@ -3989,7 +4023,7 @@ class MultipleLlmExecutionTools {
3989
4023
  // 1) OpenAI throw PipelineExecutionError: Parameter `{knowledge}` is not defined
3990
4024
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter `{knowledge}` is not defined
3991
4025
  // 3) ...
3992
- spaceTrim((block) => `
4026
+ spaceTrim$2((block) => `
3993
4027
  All execution tools of ${this.title} failed:
3994
4028
 
3995
4029
  ${block(errors
@@ -4002,7 +4036,7 @@ class MultipleLlmExecutionTools {
4002
4036
  throw new PipelineExecutionError(`You have not provided any \`LlmExecutionTools\` into ${this.title}`);
4003
4037
  }
4004
4038
  else {
4005
- throw new PipelineExecutionError(spaceTrim((block) => `
4039
+ throw new PipelineExecutionError(spaceTrim$2((block) => `
4006
4040
  You have not provided any \`LlmExecutionTools\` that support model variant "${prompt.modelRequirements.modelVariant}" into ${this.title}
4007
4041
 
4008
4042
  Available \`LlmExecutionTools\`:
@@ -4035,7 +4069,7 @@ class MultipleLlmExecutionTools {
4035
4069
  */
4036
4070
  function joinLlmExecutionTools(title, ...llmExecutionTools) {
4037
4071
  if (llmExecutionTools.length === 0) {
4038
- const warningMessage = spaceTrim(`
4072
+ const warningMessage = spaceTrim$2(`
4039
4073
  You have not provided any \`LlmExecutionTools\`
4040
4074
  This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.
4041
4075
 
@@ -4352,14 +4386,14 @@ function $registeredScrapersMessage(availableScrapers) {
4352
4386
  return { ...metadata, isMetadataAviailable, isInstalled, isAvailableInTools };
4353
4387
  });
4354
4388
  if (metadata.length === 0) {
4355
- return spaceTrim(`
4389
+ return spaceTrim$2(`
4356
4390
  **No scrapers are available**
4357
4391
 
4358
4392
  This is a unexpected behavior, you are probably using some broken version of Promptbook
4359
4393
  At least there should be available the metadata of the scrapers
4360
4394
  `);
4361
4395
  }
4362
- return spaceTrim((block) => `
4396
+ return spaceTrim$2((block) => `
4363
4397
  Available scrapers are:
4364
4398
  ${block(metadata
4365
4399
  .map(({ packageName, className, isMetadataAviailable, isInstalled, mimeTypes, isAvailableInBrowser, isAvailableInTools, }, i) => {
@@ -4470,7 +4504,7 @@ const promptbookFetch = async (urlOrRequest, init) => {
4470
4504
  else if (urlOrRequest instanceof Request) {
4471
4505
  url = urlOrRequest.url;
4472
4506
  }
4473
- throw new PromptbookFetchError(spaceTrim((block) => `
4507
+ throw new PromptbookFetchError(spaceTrim$2((block) => `
4474
4508
  Can not fetch "${url}"
4475
4509
 
4476
4510
  Fetch error:
@@ -4631,7 +4665,7 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
4631
4665
  const fileExtension = getFileExtension(filename);
4632
4666
  const mimeType = extensionToMimeType(fileExtension || '');
4633
4667
  if (!(await isFileExisting(filename, tools.fs))) {
4634
- throw new NotFoundError(spaceTrim((block) => `
4668
+ throw new NotFoundError(spaceTrim$2((block) => `
4635
4669
  Can not make source handler for file which does not exist:
4636
4670
 
4637
4671
  File:
@@ -4724,7 +4758,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
4724
4758
  // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
4725
4759
  break;
4726
4760
  }
4727
- console.warn(spaceTrim((block) => `
4761
+ console.warn(spaceTrim$2((block) => `
4728
4762
  Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
4729
4763
 
4730
4764
  The source:
@@ -4740,7 +4774,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
4740
4774
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
4741
4775
  }
4742
4776
  if (partialPieces === null) {
4743
- throw new KnowledgeScrapeError(spaceTrim((block) => `
4777
+ throw new KnowledgeScrapeError(spaceTrim$2((block) => `
4744
4778
  Cannot scrape knowledge
4745
4779
 
4746
4780
  The source:
@@ -5315,7 +5349,7 @@ const CsvFormatParser = {
5315
5349
  const { value, outputParameterName, settings, mapCallback, onProgress } = options;
5316
5350
  const csv = csvParse(value, settings);
5317
5351
  if (csv.errors.length !== 0) {
5318
- throw new CsvFormatError(spaceTrim((block) => `
5352
+ throw new CsvFormatError(spaceTrim$2((block) => `
5319
5353
  CSV parsing error
5320
5354
 
5321
5355
  Error(s) from CSV parsing:
@@ -5360,7 +5394,7 @@ const CsvFormatParser = {
5360
5394
  const { value, settings, mapCallback, onProgress } = options;
5361
5395
  const csv = csvParse(value, settings);
5362
5396
  if (csv.errors.length !== 0) {
5363
- throw new CsvFormatError(spaceTrim((block) => `
5397
+ throw new CsvFormatError(spaceTrim$2((block) => `
5364
5398
  CSV parsing error
5365
5399
 
5366
5400
  Error(s) from CSV parsing:
@@ -5570,7 +5604,7 @@ function mapAvailableToExpectedParameters(options) {
5570
5604
  }
5571
5605
  // Phase 2️⃣: Non-matching mapping
5572
5606
  if (expectedParameterNames.size !== availableParametersNames.size) {
5573
- throw new PipelineExecutionError(spaceTrim((block) => `
5607
+ throw new PipelineExecutionError(spaceTrim$2((block) => `
5574
5608
  Can not map available parameters to expected parameters
5575
5609
 
5576
5610
  Mapped parameters:
@@ -6355,7 +6389,7 @@ async function executeFormatSubvalues(options) {
6355
6389
  return /* not await */ executeAttempts({ ...options, logLlmCall });
6356
6390
  }
6357
6391
  if (jokerParameterNames.length !== 0) {
6358
- throw new UnexpectedError(spaceTrim((block) => `
6392
+ throw new UnexpectedError(spaceTrim$2((block) => `
6359
6393
  JOKER parameters are not supported together with FOREACH command
6360
6394
 
6361
6395
  [🧞‍♀️] This should be prevented in \`validatePipeline\`
@@ -6368,7 +6402,7 @@ async function executeFormatSubvalues(options) {
6368
6402
  if (formatDefinition === undefined) {
6369
6403
  throw new UnexpectedError(
6370
6404
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
6371
- spaceTrim((block) => `
6405
+ spaceTrim$2((block) => `
6372
6406
  Unsupported format "${task.foreach.formatName}"
6373
6407
 
6374
6408
  Available formats:
@@ -6385,7 +6419,7 @@ async function executeFormatSubvalues(options) {
6385
6419
  if (subvalueParser === undefined) {
6386
6420
  throw new UnexpectedError(
6387
6421
  // <- TODO: [🧠][🧐] Should be formats fixed per promptbook version or behave as plugins (=> change UnexpectedError)
6388
- spaceTrim((block) => `
6422
+ spaceTrim$2((block) => `
6389
6423
  Unsupported subformat name "${task.foreach.subformatName}" for format "${task.foreach.formatName}"
6390
6424
 
6391
6425
  Available subformat names for format "${formatDefinition.formatName}":
@@ -6425,7 +6459,7 @@ async function executeFormatSubvalues(options) {
6425
6459
  if (!(error instanceof PipelineExecutionError)) {
6426
6460
  throw error;
6427
6461
  }
6428
- const highLevelError = new PipelineExecutionError(spaceTrim((block) => `
6462
+ const highLevelError = new PipelineExecutionError(spaceTrim$2((block) => `
6429
6463
  ${error.message}
6430
6464
 
6431
6465
  This is error in FOREACH command when mapping ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
@@ -6449,7 +6483,7 @@ async function executeFormatSubvalues(options) {
6449
6483
  ...options,
6450
6484
  priority: priority + index,
6451
6485
  parameters: allSubparameters,
6452
- pipelineIdentification: spaceTrim((block) => `
6486
+ pipelineIdentification: spaceTrim$2((block) => `
6453
6487
  ${block(pipelineIdentification)}
6454
6488
  Subparameter index: ${index}
6455
6489
  `),
@@ -6458,7 +6492,7 @@ async function executeFormatSubvalues(options) {
6458
6492
  }
6459
6493
  catch (error) {
6460
6494
  if (length > BIG_DATASET_TRESHOLD) {
6461
- console.error(spaceTrim((block) => `
6495
+ console.error(spaceTrim$2((block) => `
6462
6496
  ${error.message}
6463
6497
 
6464
6498
  This is error in FOREACH command when processing ${formatDefinition.formatName} ${subvalueParser.subvalueName} data (${index + 1}/${length})
@@ -7330,8 +7364,8 @@ class MarkdownScraper {
7330
7364
  knowledgeTextPieces.map(async (knowledgeTextPiece, i) => {
7331
7365
  // Note: These are just default values, they will be overwritten by the actual values:
7332
7366
  let name = `piece-${i}`;
7333
- let title = spaceTrim(knowledgeTextPiece.substring(0, 100));
7334
- const knowledgePieceContent = spaceTrim(knowledgeTextPiece);
7367
+ let title = spaceTrim$2(knowledgeTextPiece.substring(0, 100));
7368
+ const knowledgePieceContent = spaceTrim$2(knowledgeTextPiece);
7335
7369
  let keywords = [];
7336
7370
  const index = [];
7337
7371
  /*
@@ -7344,7 +7378,7 @@ class MarkdownScraper {
7344
7378
  isCrashedOnError: true,
7345
7379
  });
7346
7380
  const { title: titleRaw = 'Untitled' } = titleResult.outputParameters;
7347
- title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
7381
+ title = spaceTrim$2(titleRaw) /* <- TODO: Maybe do in pipeline */;
7348
7382
  name = titleToName(title);
7349
7383
  // --- Keywords
7350
7384
  const keywordsResult = await prepareKeywordsExecutor({ knowledgePieceContent }).asPromise({