@promptbook/markitdown 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 +104 -79
  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 +2 -2
  24. package/umd/index.umd.js +105 -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
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-3';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2297,6 +2297,7 @@ function assertsTaskSuccessful(executionResult) {
2297
2297
  const { isSuccessful, errors, warnings } = executionResult;
2298
2298
  for (const warning of warnings) {
2299
2299
  console.warn(warning.message);
2300
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2300
2301
  }
2301
2302
  if (isSuccessful === true) {
2302
2303
  return;
@@ -2475,30 +2476,42 @@ async function forEachAsync(array, options, callbackfunction) {
2475
2476
  await Promise.all(tasks);
2476
2477
  }
2477
2478
 
2479
+ /**
2480
+ * Represents the uncertain value
2481
+ *
2482
+ * @public exported from `@promptbook/core`
2483
+ */
2484
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2485
+ /**
2486
+ * Represents the uncertain value
2487
+ *
2488
+ * @public exported from `@promptbook/core`
2489
+ */
2490
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2478
2491
  /**
2479
2492
  * Represents the usage with no resources consumed
2480
2493
  *
2481
2494
  * @public exported from `@promptbook/core`
2482
2495
  */
2483
2496
  const ZERO_USAGE = $deepFreeze({
2484
- price: { value: 0 },
2497
+ price: ZERO_VALUE,
2485
2498
  input: {
2486
- tokensCount: { value: 0 },
2487
- charactersCount: { value: 0 },
2488
- wordsCount: { value: 0 },
2489
- sentencesCount: { value: 0 },
2490
- linesCount: { value: 0 },
2491
- paragraphsCount: { value: 0 },
2492
- pagesCount: { value: 0 },
2499
+ tokensCount: ZERO_VALUE,
2500
+ charactersCount: ZERO_VALUE,
2501
+ wordsCount: ZERO_VALUE,
2502
+ sentencesCount: ZERO_VALUE,
2503
+ linesCount: ZERO_VALUE,
2504
+ paragraphsCount: ZERO_VALUE,
2505
+ pagesCount: ZERO_VALUE,
2493
2506
  },
2494
2507
  output: {
2495
- tokensCount: { value: 0 },
2496
- charactersCount: { value: 0 },
2497
- wordsCount: { value: 0 },
2498
- sentencesCount: { value: 0 },
2499
- linesCount: { value: 0 },
2500
- paragraphsCount: { value: 0 },
2501
- pagesCount: { value: 0 },
2508
+ tokensCount: ZERO_VALUE,
2509
+ charactersCount: ZERO_VALUE,
2510
+ wordsCount: ZERO_VALUE,
2511
+ sentencesCount: ZERO_VALUE,
2512
+ linesCount: ZERO_VALUE,
2513
+ paragraphsCount: ZERO_VALUE,
2514
+ pagesCount: ZERO_VALUE,
2502
2515
  },
2503
2516
  });
2504
2517
  /**
@@ -2507,24 +2520,24 @@ const ZERO_USAGE = $deepFreeze({
2507
2520
  * @public exported from `@promptbook/core`
2508
2521
  */
2509
2522
  $deepFreeze({
2510
- price: { value: 0, isUncertain: true },
2523
+ price: UNCERTAIN_ZERO_VALUE,
2511
2524
  input: {
2512
- tokensCount: { value: 0, isUncertain: true },
2513
- charactersCount: { value: 0, isUncertain: true },
2514
- wordsCount: { value: 0, isUncertain: true },
2515
- sentencesCount: { value: 0, isUncertain: true },
2516
- linesCount: { value: 0, isUncertain: true },
2517
- paragraphsCount: { value: 0, isUncertain: true },
2518
- pagesCount: { value: 0, isUncertain: true },
2525
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2526
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2527
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2528
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2529
+ linesCount: UNCERTAIN_ZERO_VALUE,
2530
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2531
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2519
2532
  },
2520
2533
  output: {
2521
- tokensCount: { value: 0, isUncertain: true },
2522
- charactersCount: { value: 0, isUncertain: true },
2523
- wordsCount: { value: 0, isUncertain: true },
2524
- sentencesCount: { value: 0, isUncertain: true },
2525
- linesCount: { value: 0, isUncertain: true },
2526
- paragraphsCount: { value: 0, isUncertain: true },
2527
- pagesCount: { value: 0, isUncertain: true },
2534
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2535
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2536
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2537
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2538
+ linesCount: UNCERTAIN_ZERO_VALUE,
2539
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2540
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2528
2541
  },
2529
2542
  });
2530
2543
  /**
@@ -2812,6 +2825,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2812
2825
  `);
2813
2826
  // TODO: [🟥] Detect browser / node and make it colorfull
2814
2827
  console.warn(warningMessage);
2828
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2815
2829
  /*
2816
2830
  return {
2817
2831
  async listModels() {
@@ -3369,63 +3383,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3369
3383
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3370
3384
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3371
3385
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3372
- let partialPieces = null;
3373
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3374
- const scrapers = arrayableToArray(tools.scrapers);
3375
- for (const scraper of scrapers) {
3376
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3377
- // <- TODO: [🦔] Implement mime-type wildcards
3378
- ) {
3379
- continue;
3380
- }
3381
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3382
- if (partialPiecesUnchecked !== null) {
3383
- partialPieces = [...partialPiecesUnchecked];
3384
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3385
- break;
3386
- }
3387
- console.warn(spaceTrim((block) => `
3388
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3386
+ try {
3387
+ let partialPieces = null;
3388
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3389
+ const scrapers = arrayableToArray(tools.scrapers);
3390
+ for (const scraper of scrapers) {
3391
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3392
+ // <- TODO: [🦔] Implement mime-type wildcards
3393
+ ) {
3394
+ continue;
3395
+ }
3396
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3397
+ if (partialPiecesUnchecked !== null) {
3398
+ partialPieces = [...partialPiecesUnchecked];
3399
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3400
+ break;
3401
+ }
3402
+ console.warn(spaceTrim((block) => `
3403
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3389
3404
 
3390
- The source:
3391
- ${block(knowledgeSource.knowledgeSourceContent
3392
- .split('\n')
3393
- .map((line) => `> ${line}`)
3394
- .join('\n'))}
3405
+ The source:
3406
+ ${block(knowledgeSource.knowledgeSourceContent
3407
+ .split('\n')
3408
+ .map((line) => `> ${line}`)
3409
+ .join('\n'))}
3395
3410
 
3396
- ${block($registeredScrapersMessage(scrapers))}
3411
+ ${block($registeredScrapersMessage(scrapers))}
3397
3412
 
3398
3413
 
3399
- `));
3400
- }
3401
- if (partialPieces === null) {
3402
- throw new KnowledgeScrapeError(spaceTrim((block) => `
3403
- Cannot scrape knowledge
3414
+ `));
3415
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3416
+ }
3417
+ if (partialPieces === null) {
3418
+ throw new KnowledgeScrapeError(spaceTrim((block) => `
3419
+ Cannot scrape knowledge
3404
3420
 
3405
- The source:
3406
- > ${block(knowledgeSource.knowledgeSourceContent
3407
- .split('\n')
3408
- .map((line) => `> ${line}`)
3409
- .join('\n'))}
3421
+ The source:
3422
+ > ${block(knowledgeSource.knowledgeSourceContent
3423
+ .split('\n')
3424
+ .map((line) => `> ${line}`)
3425
+ .join('\n'))}
3410
3426
 
3411
- No scraper found for the mime type "${sourceHandler.mimeType}"
3427
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3412
3428
 
3413
- ${block($registeredScrapersMessage(scrapers))}
3429
+ ${block($registeredScrapersMessage(scrapers))}
3414
3430
 
3415
3431
 
3416
- `));
3432
+ `));
3433
+ }
3434
+ const pieces = partialPieces.map((partialPiece) => ({
3435
+ ...partialPiece,
3436
+ sources: [
3437
+ {
3438
+ name: knowledgeSource.name,
3439
+ // line, column <- TODO: [☀]
3440
+ // <- TODO: [❎]
3441
+ },
3442
+ ],
3443
+ }));
3444
+ knowledgePreparedUnflatten[index] = pieces;
3445
+ }
3446
+ catch (error) {
3447
+ if (!(error instanceof Error)) {
3448
+ throw error;
3449
+ }
3450
+ console.warn(error);
3451
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3417
3452
  }
3418
- const pieces = partialPieces.map((partialPiece) => ({
3419
- ...partialPiece,
3420
- sources: [
3421
- {
3422
- name: knowledgeSource.name,
3423
- // line, column <- TODO: [☀]
3424
- // <- TODO: [❎]
3425
- },
3426
- ],
3427
- }));
3428
- knowledgePreparedUnflatten[index] = pieces;
3429
3453
  });
3430
3454
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3431
3455
  return knowledgePrepared;
@@ -3843,7 +3867,7 @@ function extractParameterNamesFromTask(task) {
3843
3867
  if (parameterNames.has(subparameterName)) {
3844
3868
  parameterNames.delete(subparameterName);
3845
3869
  parameterNames.add(foreach.parameterName);
3846
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
3870
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3847
3871
  }
3848
3872
  }
3849
3873
  }
@@ -5439,6 +5463,7 @@ function createPipelineExecutor(options) {
5439
5463
 
5440
5464
  @see more at https://ptbk.io/prepare-pipeline
5441
5465
  `));
5466
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5442
5467
  }
5443
5468
  let runCount = 0;
5444
5469
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {