@promptbook/markdown-utils 0.89.0-1 → 0.89.0-3

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 (25) hide show
  1. package/README.md +3 -1
  2. package/esm/index.es.js +106 -80
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +6 -4
  6. package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
  7. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  8. package/esm/typings/src/execution/PromptResult.d.ts +2 -2
  9. package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
  10. package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
  11. package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
  12. package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
  13. package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
  14. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
  15. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
  16. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
  17. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
  18. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
  19. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
  20. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
  21. package/esm/typings/src/playground/BrjappConnector.d.ts +3 -0
  22. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  23. package/package.json +1 -1
  24. package/umd/index.umd.js +106 -80
  25. package/umd/index.umd.js.map +1 -1
package/README.md CHANGED
@@ -200,7 +200,7 @@ Each part of the book defines one of 3 circles:
200
200
 
201
201
  ### **What:** Workflows, Tasks and Parameters
202
202
 
203
- What work needs to be done. Each book defines a workflow, which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
203
+ What work needs to be done. Each book defines a [workflow *(scenario or pipeline)*](https://github.com/webgptorg/promptbook/discussions/88), which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
204
204
 
205
205
  **Related commands:**
206
206
 
@@ -310,6 +310,8 @@ The following glossary is used to clarify certain concepts:
310
310
 
311
311
 
312
312
 
313
+
314
+
313
315
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
314
316
 
315
317
 
package/esm/index.es.js CHANGED
@@ -25,7 +25,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-3';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1996,6 +1996,7 @@ function assertsTaskSuccessful(executionResult) {
1996
1996
  const { isSuccessful, errors, warnings } = executionResult;
1997
1997
  for (const warning of warnings) {
1998
1998
  console.warn(warning.message);
1999
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
1999
2000
  }
2000
2001
  if (isSuccessful === true) {
2001
2002
  return;
@@ -2174,30 +2175,42 @@ async function forEachAsync(array, options, callbackfunction) {
2174
2175
  await Promise.all(tasks);
2175
2176
  }
2176
2177
 
2178
+ /**
2179
+ * Represents the uncertain value
2180
+ *
2181
+ * @public exported from `@promptbook/core`
2182
+ */
2183
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2184
+ /**
2185
+ * Represents the uncertain value
2186
+ *
2187
+ * @public exported from `@promptbook/core`
2188
+ */
2189
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2177
2190
  /**
2178
2191
  * Represents the usage with no resources consumed
2179
2192
  *
2180
2193
  * @public exported from `@promptbook/core`
2181
2194
  */
2182
2195
  const ZERO_USAGE = $deepFreeze({
2183
- price: { value: 0 },
2196
+ price: ZERO_VALUE,
2184
2197
  input: {
2185
- tokensCount: { value: 0 },
2186
- charactersCount: { value: 0 },
2187
- wordsCount: { value: 0 },
2188
- sentencesCount: { value: 0 },
2189
- linesCount: { value: 0 },
2190
- paragraphsCount: { value: 0 },
2191
- pagesCount: { value: 0 },
2198
+ tokensCount: ZERO_VALUE,
2199
+ charactersCount: ZERO_VALUE,
2200
+ wordsCount: ZERO_VALUE,
2201
+ sentencesCount: ZERO_VALUE,
2202
+ linesCount: ZERO_VALUE,
2203
+ paragraphsCount: ZERO_VALUE,
2204
+ pagesCount: ZERO_VALUE,
2192
2205
  },
2193
2206
  output: {
2194
- tokensCount: { value: 0 },
2195
- charactersCount: { value: 0 },
2196
- wordsCount: { value: 0 },
2197
- sentencesCount: { value: 0 },
2198
- linesCount: { value: 0 },
2199
- paragraphsCount: { value: 0 },
2200
- pagesCount: { value: 0 },
2207
+ tokensCount: ZERO_VALUE,
2208
+ charactersCount: ZERO_VALUE,
2209
+ wordsCount: ZERO_VALUE,
2210
+ sentencesCount: ZERO_VALUE,
2211
+ linesCount: ZERO_VALUE,
2212
+ paragraphsCount: ZERO_VALUE,
2213
+ pagesCount: ZERO_VALUE,
2201
2214
  },
2202
2215
  });
2203
2216
  /**
@@ -2206,24 +2219,24 @@ const ZERO_USAGE = $deepFreeze({
2206
2219
  * @public exported from `@promptbook/core`
2207
2220
  */
2208
2221
  $deepFreeze({
2209
- price: { value: 0, isUncertain: true },
2222
+ price: UNCERTAIN_ZERO_VALUE,
2210
2223
  input: {
2211
- tokensCount: { value: 0, isUncertain: true },
2212
- charactersCount: { value: 0, isUncertain: true },
2213
- wordsCount: { value: 0, isUncertain: true },
2214
- sentencesCount: { value: 0, isUncertain: true },
2215
- linesCount: { value: 0, isUncertain: true },
2216
- paragraphsCount: { value: 0, isUncertain: true },
2217
- pagesCount: { value: 0, isUncertain: true },
2224
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2225
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2226
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2227
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2228
+ linesCount: UNCERTAIN_ZERO_VALUE,
2229
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2230
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2218
2231
  },
2219
2232
  output: {
2220
- tokensCount: { value: 0, isUncertain: true },
2221
- charactersCount: { value: 0, isUncertain: true },
2222
- wordsCount: { value: 0, isUncertain: true },
2223
- sentencesCount: { value: 0, isUncertain: true },
2224
- linesCount: { value: 0, isUncertain: true },
2225
- paragraphsCount: { value: 0, isUncertain: true },
2226
- pagesCount: { value: 0, isUncertain: true },
2233
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2234
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2235
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2236
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2237
+ linesCount: UNCERTAIN_ZERO_VALUE,
2238
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2239
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2227
2240
  },
2228
2241
  });
2229
2242
  /**
@@ -2511,6 +2524,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2511
2524
  `);
2512
2525
  // TODO: [🟥] Detect browser / node and make it colorfull
2513
2526
  console.warn(warningMessage);
2527
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2514
2528
  /*
2515
2529
  return {
2516
2530
  async listModels() {
@@ -3454,63 +3468,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3454
3468
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3455
3469
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3456
3470
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3457
- let partialPieces = null;
3458
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3459
- const scrapers = arrayableToArray(tools.scrapers);
3460
- for (const scraper of scrapers) {
3461
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3462
- // <- TODO: [🦔] Implement mime-type wildcards
3463
- ) {
3464
- continue;
3465
- }
3466
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3467
- if (partialPiecesUnchecked !== null) {
3468
- partialPieces = [...partialPiecesUnchecked];
3469
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3470
- break;
3471
- }
3472
- console.warn(spaceTrim((block) => `
3473
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3471
+ try {
3472
+ let partialPieces = null;
3473
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3474
+ const scrapers = arrayableToArray(tools.scrapers);
3475
+ for (const scraper of scrapers) {
3476
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3477
+ // <- TODO: [🦔] Implement mime-type wildcards
3478
+ ) {
3479
+ continue;
3480
+ }
3481
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3482
+ if (partialPiecesUnchecked !== null) {
3483
+ partialPieces = [...partialPiecesUnchecked];
3484
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3485
+ break;
3486
+ }
3487
+ console.warn(spaceTrim((block) => `
3488
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3474
3489
 
3475
- The source:
3476
- ${block(knowledgeSource.knowledgeSourceContent
3477
- .split('\n')
3478
- .map((line) => `> ${line}`)
3479
- .join('\n'))}
3490
+ The source:
3491
+ ${block(knowledgeSource.knowledgeSourceContent
3492
+ .split('\n')
3493
+ .map((line) => `> ${line}`)
3494
+ .join('\n'))}
3480
3495
 
3481
- ${block($registeredScrapersMessage(scrapers))}
3496
+ ${block($registeredScrapersMessage(scrapers))}
3482
3497
 
3483
3498
 
3484
- `));
3485
- }
3486
- if (partialPieces === null) {
3487
- throw new KnowledgeScrapeError(spaceTrim((block) => `
3488
- Cannot scrape knowledge
3499
+ `));
3500
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3501
+ }
3502
+ if (partialPieces === null) {
3503
+ throw new KnowledgeScrapeError(spaceTrim((block) => `
3504
+ Cannot scrape knowledge
3489
3505
 
3490
- The source:
3491
- > ${block(knowledgeSource.knowledgeSourceContent
3492
- .split('\n')
3493
- .map((line) => `> ${line}`)
3494
- .join('\n'))}
3506
+ The source:
3507
+ > ${block(knowledgeSource.knowledgeSourceContent
3508
+ .split('\n')
3509
+ .map((line) => `> ${line}`)
3510
+ .join('\n'))}
3495
3511
 
3496
- No scraper found for the mime type "${sourceHandler.mimeType}"
3512
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3497
3513
 
3498
- ${block($registeredScrapersMessage(scrapers))}
3514
+ ${block($registeredScrapersMessage(scrapers))}
3499
3515
 
3500
3516
 
3501
- `));
3517
+ `));
3518
+ }
3519
+ const pieces = partialPieces.map((partialPiece) => ({
3520
+ ...partialPiece,
3521
+ sources: [
3522
+ {
3523
+ name: knowledgeSource.name,
3524
+ // line, column <- TODO: [☀]
3525
+ // <- TODO: [❎]
3526
+ },
3527
+ ],
3528
+ }));
3529
+ knowledgePreparedUnflatten[index] = pieces;
3530
+ }
3531
+ catch (error) {
3532
+ if (!(error instanceof Error)) {
3533
+ throw error;
3534
+ }
3535
+ console.warn(error);
3536
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3502
3537
  }
3503
- const pieces = partialPieces.map((partialPiece) => ({
3504
- ...partialPiece,
3505
- sources: [
3506
- {
3507
- name: knowledgeSource.name,
3508
- // line, column <- TODO: [☀]
3509
- // <- TODO: [❎]
3510
- },
3511
- ],
3512
- }));
3513
- knowledgePreparedUnflatten[index] = pieces;
3514
3538
  });
3515
3539
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3516
3540
  return knowledgePrepared;
@@ -3928,7 +3952,7 @@ function extractParameterNamesFromTask(task) {
3928
3952
  if (parameterNames.has(subparameterName)) {
3929
3953
  parameterNames.delete(subparameterName);
3930
3954
  parameterNames.add(foreach.parameterName);
3931
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
3955
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3932
3956
  }
3933
3957
  }
3934
3958
  }
@@ -5422,6 +5446,7 @@ function createPipelineExecutor(options) {
5422
5446
 
5423
5447
  @see more at https://ptbk.io/prepare-pipeline
5424
5448
  `));
5449
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5425
5450
  }
5426
5451
  let runCount = 0;
5427
5452
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
@@ -5696,7 +5721,8 @@ function addAutoGeneratedSection(content, options) {
5696
5721
  `));
5697
5722
  }
5698
5723
  console.warn(`No place where to put the section <!--${sectionName}-->, using the end of the file`);
5699
- // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
5724
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5725
+ // <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
5700
5726
  return spaceTrim$1((block) => `
5701
5727
  ${block(content)}
5702
5728