@promptbook/remote-server 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 +109 -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 +109 -79
  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
@@ -31,7 +31,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
31
31
  * @generated
32
32
  * @see https://github.com/webgptorg/promptbook
33
33
  */
34
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
34
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-3';
35
35
  /**
36
36
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
37
37
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -694,6 +694,7 @@ function $execCommand(options) {
694
694
  }
695
695
  else {
696
696
  console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
697
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
697
698
  resolve('Command exceeded time limit');
698
699
  }
699
700
  });
@@ -719,6 +720,7 @@ function $execCommand(options) {
719
720
  output.push(stderr.toString());
720
721
  if (isVerbose && stderr.toString().trim()) {
721
722
  console.warn(stderr.toString());
723
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
722
724
  }
723
725
  });
724
726
  const finishWithCode = (code) => {
@@ -730,6 +732,7 @@ function $execCommand(options) {
730
732
  else {
731
733
  if (isVerbose) {
732
734
  console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
735
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
733
736
  }
734
737
  resolve(spaceTrim(output.join('\n')));
735
738
  }
@@ -751,6 +754,7 @@ function $execCommand(options) {
751
754
  else {
752
755
  if (isVerbose) {
753
756
  console.warn(error);
757
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
754
758
  }
755
759
  resolve(spaceTrim(output.join('\n')));
756
760
  }
@@ -1819,6 +1823,7 @@ function assertsTaskSuccessful(executionResult) {
1819
1823
  const { isSuccessful, errors, warnings } = executionResult;
1820
1824
  for (const warning of warnings) {
1821
1825
  console.warn(warning.message);
1826
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
1822
1827
  }
1823
1828
  if (isSuccessful === true) {
1824
1829
  return;
@@ -2420,30 +2425,42 @@ async function forEachAsync(array, options, callbackfunction) {
2420
2425
  await Promise.all(tasks);
2421
2426
  }
2422
2427
 
2428
+ /**
2429
+ * Represents the uncertain value
2430
+ *
2431
+ * @public exported from `@promptbook/core`
2432
+ */
2433
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2434
+ /**
2435
+ * Represents the uncertain value
2436
+ *
2437
+ * @public exported from `@promptbook/core`
2438
+ */
2439
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2423
2440
  /**
2424
2441
  * Represents the usage with no resources consumed
2425
2442
  *
2426
2443
  * @public exported from `@promptbook/core`
2427
2444
  */
2428
2445
  const ZERO_USAGE = $deepFreeze({
2429
- price: { value: 0 },
2446
+ price: ZERO_VALUE,
2430
2447
  input: {
2431
- tokensCount: { value: 0 },
2432
- charactersCount: { value: 0 },
2433
- wordsCount: { value: 0 },
2434
- sentencesCount: { value: 0 },
2435
- linesCount: { value: 0 },
2436
- paragraphsCount: { value: 0 },
2437
- pagesCount: { value: 0 },
2448
+ tokensCount: ZERO_VALUE,
2449
+ charactersCount: ZERO_VALUE,
2450
+ wordsCount: ZERO_VALUE,
2451
+ sentencesCount: ZERO_VALUE,
2452
+ linesCount: ZERO_VALUE,
2453
+ paragraphsCount: ZERO_VALUE,
2454
+ pagesCount: ZERO_VALUE,
2438
2455
  },
2439
2456
  output: {
2440
- tokensCount: { value: 0 },
2441
- charactersCount: { value: 0 },
2442
- wordsCount: { value: 0 },
2443
- sentencesCount: { value: 0 },
2444
- linesCount: { value: 0 },
2445
- paragraphsCount: { value: 0 },
2446
- pagesCount: { value: 0 },
2457
+ tokensCount: ZERO_VALUE,
2458
+ charactersCount: ZERO_VALUE,
2459
+ wordsCount: ZERO_VALUE,
2460
+ sentencesCount: ZERO_VALUE,
2461
+ linesCount: ZERO_VALUE,
2462
+ paragraphsCount: ZERO_VALUE,
2463
+ pagesCount: ZERO_VALUE,
2447
2464
  },
2448
2465
  });
2449
2466
  /**
@@ -2452,24 +2469,24 @@ const ZERO_USAGE = $deepFreeze({
2452
2469
  * @public exported from `@promptbook/core`
2453
2470
  */
2454
2471
  $deepFreeze({
2455
- price: { value: 0, isUncertain: true },
2472
+ price: UNCERTAIN_ZERO_VALUE,
2456
2473
  input: {
2457
- tokensCount: { value: 0, isUncertain: true },
2458
- charactersCount: { value: 0, isUncertain: true },
2459
- wordsCount: { value: 0, isUncertain: true },
2460
- sentencesCount: { value: 0, isUncertain: true },
2461
- linesCount: { value: 0, isUncertain: true },
2462
- paragraphsCount: { value: 0, isUncertain: true },
2463
- pagesCount: { value: 0, isUncertain: true },
2474
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2475
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2476
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2477
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2478
+ linesCount: UNCERTAIN_ZERO_VALUE,
2479
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2480
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2464
2481
  },
2465
2482
  output: {
2466
- tokensCount: { value: 0, isUncertain: true },
2467
- charactersCount: { value: 0, isUncertain: true },
2468
- wordsCount: { value: 0, isUncertain: true },
2469
- sentencesCount: { value: 0, isUncertain: true },
2470
- linesCount: { value: 0, isUncertain: true },
2471
- paragraphsCount: { value: 0, isUncertain: true },
2472
- pagesCount: { value: 0, isUncertain: true },
2483
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2484
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2485
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2486
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2487
+ linesCount: UNCERTAIN_ZERO_VALUE,
2488
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2489
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2473
2490
  },
2474
2491
  });
2475
2492
  /**
@@ -2757,6 +2774,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2757
2774
  `);
2758
2775
  // TODO: [🟥] Detect browser / node and make it colorfull
2759
2776
  console.warn(warningMessage);
2777
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2760
2778
  /*
2761
2779
  return {
2762
2780
  async listModels() {
@@ -3700,63 +3718,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3700
3718
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3701
3719
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3702
3720
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3703
- let partialPieces = null;
3704
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3705
- const scrapers = arrayableToArray(tools.scrapers);
3706
- for (const scraper of scrapers) {
3707
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3708
- // <- TODO: [🦔] Implement mime-type wildcards
3709
- ) {
3710
- continue;
3711
- }
3712
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3713
- if (partialPiecesUnchecked !== null) {
3714
- partialPieces = [...partialPiecesUnchecked];
3715
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3716
- break;
3717
- }
3718
- console.warn(spaceTrim$1((block) => `
3719
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3721
+ try {
3722
+ let partialPieces = null;
3723
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3724
+ const scrapers = arrayableToArray(tools.scrapers);
3725
+ for (const scraper of scrapers) {
3726
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3727
+ // <- TODO: [🦔] Implement mime-type wildcards
3728
+ ) {
3729
+ continue;
3730
+ }
3731
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3732
+ if (partialPiecesUnchecked !== null) {
3733
+ partialPieces = [...partialPiecesUnchecked];
3734
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3735
+ break;
3736
+ }
3737
+ console.warn(spaceTrim$1((block) => `
3738
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3720
3739
 
3721
- The source:
3722
- ${block(knowledgeSource.knowledgeSourceContent
3723
- .split('\n')
3724
- .map((line) => `> ${line}`)
3725
- .join('\n'))}
3740
+ The source:
3741
+ ${block(knowledgeSource.knowledgeSourceContent
3742
+ .split('\n')
3743
+ .map((line) => `> ${line}`)
3744
+ .join('\n'))}
3726
3745
 
3727
- ${block($registeredScrapersMessage(scrapers))}
3746
+ ${block($registeredScrapersMessage(scrapers))}
3728
3747
 
3729
3748
 
3730
- `));
3731
- }
3732
- if (partialPieces === null) {
3733
- throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3734
- Cannot scrape knowledge
3749
+ `));
3750
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3751
+ }
3752
+ if (partialPieces === null) {
3753
+ throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3754
+ Cannot scrape knowledge
3735
3755
 
3736
- The source:
3737
- > ${block(knowledgeSource.knowledgeSourceContent
3738
- .split('\n')
3739
- .map((line) => `> ${line}`)
3740
- .join('\n'))}
3756
+ The source:
3757
+ > ${block(knowledgeSource.knowledgeSourceContent
3758
+ .split('\n')
3759
+ .map((line) => `> ${line}`)
3760
+ .join('\n'))}
3741
3761
 
3742
- No scraper found for the mime type "${sourceHandler.mimeType}"
3762
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3743
3763
 
3744
- ${block($registeredScrapersMessage(scrapers))}
3764
+ ${block($registeredScrapersMessage(scrapers))}
3745
3765
 
3746
3766
 
3747
- `));
3767
+ `));
3768
+ }
3769
+ const pieces = partialPieces.map((partialPiece) => ({
3770
+ ...partialPiece,
3771
+ sources: [
3772
+ {
3773
+ name: knowledgeSource.name,
3774
+ // line, column <- TODO: [☀]
3775
+ // <- TODO: [❎]
3776
+ },
3777
+ ],
3778
+ }));
3779
+ knowledgePreparedUnflatten[index] = pieces;
3780
+ }
3781
+ catch (error) {
3782
+ if (!(error instanceof Error)) {
3783
+ throw error;
3784
+ }
3785
+ console.warn(error);
3786
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3748
3787
  }
3749
- const pieces = partialPieces.map((partialPiece) => ({
3750
- ...partialPiece,
3751
- sources: [
3752
- {
3753
- name: knowledgeSource.name,
3754
- // line, column <- TODO: [☀]
3755
- // <- TODO: [❎]
3756
- },
3757
- ],
3758
- }));
3759
- knowledgePreparedUnflatten[index] = pieces;
3760
3788
  });
3761
3789
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3762
3790
  return knowledgePrepared;
@@ -4174,7 +4202,7 @@ function extractParameterNamesFromTask(task) {
4174
4202
  if (parameterNames.has(subparameterName)) {
4175
4203
  parameterNames.delete(subparameterName);
4176
4204
  parameterNames.add(foreach.parameterName);
4177
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
4205
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
4178
4206
  }
4179
4207
  }
4180
4208
  }
@@ -5787,6 +5815,7 @@ function createPipelineExecutor(options) {
5787
5815
 
5788
5816
  @see more at https://ptbk.io/prepare-pipeline
5789
5817
  `));
5818
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5790
5819
  }
5791
5820
  let runCount = 0;
5792
5821
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
@@ -6812,6 +6841,7 @@ function startRemoteServer(options) {
6812
6841
  https://github.com/webgptorg/promptbook
6813
6842
  `));
6814
6843
  });
6844
+ // TODO: !!!!!! Add login route
6815
6845
  app.get(`${rootPath}/books`, async (request, response) => {
6816
6846
  if (collection === null) {
6817
6847
  response.status(500).send('No collection available');