@promptbook/website-crawler 0.89.0-1 → 0.89.0-11

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 (52) hide show
  1. package/README.md +3 -1
  2. package/esm/index.es.js +150 -85
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +16 -4
  5. package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
  6. package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
  7. package/esm/typings/src/_packages/types.index.d.ts +18 -20
  8. package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
  9. package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
  10. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +15 -0
  11. package/esm/typings/src/config.d.ts +15 -8
  12. package/esm/typings/src/errors/0-index.d.ts +6 -0
  13. package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
  14. package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
  15. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  16. package/esm/typings/src/execution/PromptResult.d.ts +2 -2
  17. package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
  18. package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
  19. package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
  20. package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
  21. package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
  22. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
  23. package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
  24. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
  25. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
  26. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +36 -1
  27. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
  28. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
  29. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
  30. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  31. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
  32. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
  33. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
  34. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
  35. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
  36. package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
  37. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
  38. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  39. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  40. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  41. package/esm/typings/src/remote-server/startRemoteServer.d.ts +2 -2
  42. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
  43. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +73 -3
  44. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  45. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +37 -0
  46. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  47. package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
  48. package/package.json +2 -2
  49. package/umd/index.umd.js +151 -86
  50. package/umd/index.umd.js.map +1 -1
  51. package/esm/typings/src/playground/BrjappConnector.d.ts +0 -64
  52. package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
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
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
29
29
  * @generated
30
30
  * @see https://github.com/webgptorg/promptbook
31
31
  */
32
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
33
33
  /**
34
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
35
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -190,6 +190,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
190
190
  */
191
191
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
192
192
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
193
+ // TODO: !!!!!! Just .promptbook dir, hardocode others
193
194
  /**
194
195
  * Where to store the temporary downloads
195
196
  *
@@ -241,7 +242,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
241
242
  true);
242
243
  /**
243
244
  * Note: [💞] Ignore a discrepancy between file name and entity name
244
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
245
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
245
246
  */
246
247
 
247
248
  /**
@@ -2285,6 +2286,19 @@ class CsvFormatError extends AbstractFormatError {
2285
2286
  }
2286
2287
  }
2287
2288
 
2289
+ /**
2290
+ * AuthenticationError is thrown from login function which is dependency of remote server
2291
+ *
2292
+ * @public exported from `@promptbook/core`
2293
+ */
2294
+ class AuthenticationError extends Error {
2295
+ constructor(message) {
2296
+ super(message);
2297
+ this.name = 'AuthenticationError';
2298
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
2299
+ }
2300
+ }
2301
+
2288
2302
  /**
2289
2303
  * This error indicates that the pipeline collection cannot be propperly loaded
2290
2304
  *
@@ -2327,6 +2341,19 @@ class LimitReachedError extends Error {
2327
2341
  }
2328
2342
  }
2329
2343
 
2344
+ /**
2345
+ * Error thrown when a fetch request fails
2346
+ *
2347
+ * @public exported from `@promptbook/core`
2348
+ */
2349
+ class PromptbookFetchError extends Error {
2350
+ constructor(message) {
2351
+ super(message);
2352
+ this.name = 'PromptbookFetchError';
2353
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
2354
+ }
2355
+ }
2356
+
2330
2357
  /**
2331
2358
  * Index of all custom errors
2332
2359
  *
@@ -2364,6 +2391,8 @@ const COMMON_JAVASCRIPT_ERRORS = {
2364
2391
  TypeError,
2365
2392
  URIError,
2366
2393
  AggregateError,
2394
+ AuthenticationError,
2395
+ PromptbookFetchError,
2367
2396
  /*
2368
2397
  Note: Not widely supported
2369
2398
  > InternalError,
@@ -2425,6 +2454,7 @@ function assertsTaskSuccessful(executionResult) {
2425
2454
  const { isSuccessful, errors, warnings } = executionResult;
2426
2455
  for (const warning of warnings) {
2427
2456
  console.warn(warning.message);
2457
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2428
2458
  }
2429
2459
  if (isSuccessful === true) {
2430
2460
  return;
@@ -2562,6 +2592,10 @@ function serializeError(error) {
2562
2592
 
2563
2593
  Cannot serialize error with name "${name}"
2564
2594
 
2595
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2596
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2597
+
2598
+
2565
2599
  ${block(stack || message)}
2566
2600
 
2567
2601
  `));
@@ -2603,30 +2637,42 @@ async function forEachAsync(array, options, callbackfunction) {
2603
2637
  await Promise.all(tasks);
2604
2638
  }
2605
2639
 
2640
+ /**
2641
+ * Represents the uncertain value
2642
+ *
2643
+ * @public exported from `@promptbook/core`
2644
+ */
2645
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2646
+ /**
2647
+ * Represents the uncertain value
2648
+ *
2649
+ * @public exported from `@promptbook/core`
2650
+ */
2651
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2606
2652
  /**
2607
2653
  * Represents the usage with no resources consumed
2608
2654
  *
2609
2655
  * @public exported from `@promptbook/core`
2610
2656
  */
2611
2657
  const ZERO_USAGE = $deepFreeze({
2612
- price: { value: 0 },
2658
+ price: ZERO_VALUE,
2613
2659
  input: {
2614
- tokensCount: { value: 0 },
2615
- charactersCount: { value: 0 },
2616
- wordsCount: { value: 0 },
2617
- sentencesCount: { value: 0 },
2618
- linesCount: { value: 0 },
2619
- paragraphsCount: { value: 0 },
2620
- pagesCount: { value: 0 },
2660
+ tokensCount: ZERO_VALUE,
2661
+ charactersCount: ZERO_VALUE,
2662
+ wordsCount: ZERO_VALUE,
2663
+ sentencesCount: ZERO_VALUE,
2664
+ linesCount: ZERO_VALUE,
2665
+ paragraphsCount: ZERO_VALUE,
2666
+ pagesCount: ZERO_VALUE,
2621
2667
  },
2622
2668
  output: {
2623
- tokensCount: { value: 0 },
2624
- charactersCount: { value: 0 },
2625
- wordsCount: { value: 0 },
2626
- sentencesCount: { value: 0 },
2627
- linesCount: { value: 0 },
2628
- paragraphsCount: { value: 0 },
2629
- pagesCount: { value: 0 },
2669
+ tokensCount: ZERO_VALUE,
2670
+ charactersCount: ZERO_VALUE,
2671
+ wordsCount: ZERO_VALUE,
2672
+ sentencesCount: ZERO_VALUE,
2673
+ linesCount: ZERO_VALUE,
2674
+ paragraphsCount: ZERO_VALUE,
2675
+ pagesCount: ZERO_VALUE,
2630
2676
  },
2631
2677
  });
2632
2678
  /**
@@ -2635,24 +2681,24 @@ const ZERO_USAGE = $deepFreeze({
2635
2681
  * @public exported from `@promptbook/core`
2636
2682
  */
2637
2683
  $deepFreeze({
2638
- price: { value: 0, isUncertain: true },
2684
+ price: UNCERTAIN_ZERO_VALUE,
2639
2685
  input: {
2640
- tokensCount: { value: 0, isUncertain: true },
2641
- charactersCount: { value: 0, isUncertain: true },
2642
- wordsCount: { value: 0, isUncertain: true },
2643
- sentencesCount: { value: 0, isUncertain: true },
2644
- linesCount: { value: 0, isUncertain: true },
2645
- paragraphsCount: { value: 0, isUncertain: true },
2646
- pagesCount: { value: 0, isUncertain: true },
2686
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2687
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2688
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2689
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2690
+ linesCount: UNCERTAIN_ZERO_VALUE,
2691
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2692
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2647
2693
  },
2648
2694
  output: {
2649
- tokensCount: { value: 0, isUncertain: true },
2650
- charactersCount: { value: 0, isUncertain: true },
2651
- wordsCount: { value: 0, isUncertain: true },
2652
- sentencesCount: { value: 0, isUncertain: true },
2653
- linesCount: { value: 0, isUncertain: true },
2654
- paragraphsCount: { value: 0, isUncertain: true },
2655
- pagesCount: { value: 0, isUncertain: true },
2695
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2696
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2697
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2698
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2699
+ linesCount: UNCERTAIN_ZERO_VALUE,
2700
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2701
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2656
2702
  },
2657
2703
  });
2658
2704
  /**
@@ -2940,6 +2986,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2940
2986
  `);
2941
2987
  // TODO: [🟥] Detect browser / node and make it colorfull
2942
2988
  console.warn(warningMessage);
2989
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2943
2990
  /*
2944
2991
  return {
2945
2992
  async listModels() {
@@ -3211,17 +3258,24 @@ function mimeTypeToExtension(value) {
3211
3258
  /**
3212
3259
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3213
3260
  *
3214
- * @private as default `fetch` function used in Promptbook scrapers
3261
+ * @public exported from `@promptbook/core`
3215
3262
  */
3216
- const scraperFetch = async (url, init) => {
3263
+ const promptbookFetch = async (urlOrRequest, init) => {
3217
3264
  try {
3218
- return await fetch(url, init);
3265
+ return await fetch(urlOrRequest, init);
3219
3266
  }
3220
3267
  catch (error) {
3221
3268
  if (!(error instanceof Error)) {
3222
3269
  throw error;
3223
3270
  }
3224
- throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3271
+ let url;
3272
+ if (typeof urlOrRequest === 'string') {
3273
+ url = urlOrRequest;
3274
+ }
3275
+ else if (urlOrRequest instanceof Request) {
3276
+ url = urlOrRequest.url;
3277
+ }
3278
+ throw new PromptbookFetchError(spaceTrim$1((block) => `
3225
3279
  Can not fetch "${url}"
3226
3280
 
3227
3281
  Fetch error:
@@ -3242,7 +3296,7 @@ const scraperFetch = async (url, init) => {
3242
3296
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3243
3297
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
3244
3298
  var _a;
3245
- const { fetch = scraperFetch } = tools;
3299
+ const { fetch = promptbookFetch } = tools;
3246
3300
  const { knowledgeSourceContent } = knowledgeSource;
3247
3301
  let { name } = knowledgeSource;
3248
3302
  const { rootDirname = null,
@@ -3383,63 +3437,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3383
3437
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3384
3438
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3385
3439
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3386
- let partialPieces = null;
3387
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3388
- const scrapers = arrayableToArray(tools.scrapers);
3389
- for (const scraper of scrapers) {
3390
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3391
- // <- TODO: [🦔] Implement mime-type wildcards
3392
- ) {
3393
- continue;
3394
- }
3395
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3396
- if (partialPiecesUnchecked !== null) {
3397
- partialPieces = [...partialPiecesUnchecked];
3398
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3399
- break;
3400
- }
3401
- console.warn(spaceTrim$1((block) => `
3402
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3440
+ try {
3441
+ let partialPieces = null;
3442
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3443
+ const scrapers = arrayableToArray(tools.scrapers);
3444
+ for (const scraper of scrapers) {
3445
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3446
+ // <- TODO: [🦔] Implement mime-type wildcards
3447
+ ) {
3448
+ continue;
3449
+ }
3450
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3451
+ if (partialPiecesUnchecked !== null) {
3452
+ partialPieces = [...partialPiecesUnchecked];
3453
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3454
+ break;
3455
+ }
3456
+ console.warn(spaceTrim$1((block) => `
3457
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3403
3458
 
3404
- The source:
3405
- ${block(knowledgeSource.knowledgeSourceContent
3406
- .split('\n')
3407
- .map((line) => `> ${line}`)
3408
- .join('\n'))}
3459
+ The source:
3460
+ ${block(knowledgeSource.knowledgeSourceContent
3461
+ .split('\n')
3462
+ .map((line) => `> ${line}`)
3463
+ .join('\n'))}
3409
3464
 
3410
- ${block($registeredScrapersMessage(scrapers))}
3465
+ ${block($registeredScrapersMessage(scrapers))}
3411
3466
 
3412
3467
 
3413
- `));
3414
- }
3415
- if (partialPieces === null) {
3416
- throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3417
- Cannot scrape knowledge
3468
+ `));
3469
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3470
+ }
3471
+ if (partialPieces === null) {
3472
+ throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3473
+ Cannot scrape knowledge
3418
3474
 
3419
- The source:
3420
- > ${block(knowledgeSource.knowledgeSourceContent
3421
- .split('\n')
3422
- .map((line) => `> ${line}`)
3423
- .join('\n'))}
3475
+ The source:
3476
+ > ${block(knowledgeSource.knowledgeSourceContent
3477
+ .split('\n')
3478
+ .map((line) => `> ${line}`)
3479
+ .join('\n'))}
3424
3480
 
3425
- No scraper found for the mime type "${sourceHandler.mimeType}"
3481
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3426
3482
 
3427
- ${block($registeredScrapersMessage(scrapers))}
3483
+ ${block($registeredScrapersMessage(scrapers))}
3428
3484
 
3429
3485
 
3430
- `));
3486
+ `));
3487
+ }
3488
+ const pieces = partialPieces.map((partialPiece) => ({
3489
+ ...partialPiece,
3490
+ sources: [
3491
+ {
3492
+ name: knowledgeSource.name,
3493
+ // line, column <- TODO: [☀]
3494
+ // <- TODO: [❎]
3495
+ },
3496
+ ],
3497
+ }));
3498
+ knowledgePreparedUnflatten[index] = pieces;
3499
+ }
3500
+ catch (error) {
3501
+ if (!(error instanceof Error)) {
3502
+ throw error;
3503
+ }
3504
+ console.warn(error);
3505
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3431
3506
  }
3432
- const pieces = partialPieces.map((partialPiece) => ({
3433
- ...partialPiece,
3434
- sources: [
3435
- {
3436
- name: knowledgeSource.name,
3437
- // line, column <- TODO: [☀]
3438
- // <- TODO: [❎]
3439
- },
3440
- ],
3441
- }));
3442
- knowledgePreparedUnflatten[index] = pieces;
3443
3507
  });
3444
3508
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3445
3509
  return knowledgePrepared;
@@ -3857,7 +3921,7 @@ function extractParameterNamesFromTask(task) {
3857
3921
  if (parameterNames.has(subparameterName)) {
3858
3922
  parameterNames.delete(subparameterName);
3859
3923
  parameterNames.add(foreach.parameterName);
3860
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
3924
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3861
3925
  }
3862
3926
  }
3863
3927
  }
@@ -5453,6 +5517,7 @@ function createPipelineExecutor(options) {
5453
5517
 
5454
5518
  @see more at https://ptbk.io/prepare-pipeline
5455
5519
  `));
5520
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5456
5521
  }
5457
5522
  let runCount = 0;
5458
5523
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {