@promptbook/pdf 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
@@ -202,7 +202,7 @@ Each part of the book defines one of 3 circles:
202
202
 
203
203
  ### **What:** Workflows, Tasks and Parameters
204
204
 
205
- 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.
205
+ 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.
206
206
 
207
207
  **Related commands:**
208
208
 
@@ -312,6 +312,8 @@ The following glossary is used to clarify certain concepts:
312
312
 
313
313
 
314
314
 
315
+
316
+
315
317
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
316
318
 
317
319
 
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-11';
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
@@ -160,6 +160,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
160
160
  */
161
161
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
162
162
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
163
+ // TODO: !!!!!! Just .promptbook dir, hardocode others
163
164
  /**
164
165
  * Where to store the temporary downloads
165
166
  *
@@ -211,7 +212,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
211
212
  true);
212
213
  /**
213
214
  * Note: [💞] Ignore a discrepancy between file name and entity name
214
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
215
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
215
216
  */
216
217
 
217
218
  /**
@@ -2147,6 +2148,19 @@ class CsvFormatError extends AbstractFormatError {
2147
2148
  }
2148
2149
  }
2149
2150
 
2151
+ /**
2152
+ * AuthenticationError is thrown from login function which is dependency of remote server
2153
+ *
2154
+ * @public exported from `@promptbook/core`
2155
+ */
2156
+ class AuthenticationError extends Error {
2157
+ constructor(message) {
2158
+ super(message);
2159
+ this.name = 'AuthenticationError';
2160
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
2161
+ }
2162
+ }
2163
+
2150
2164
  /**
2151
2165
  * This error indicates that the pipeline collection cannot be propperly loaded
2152
2166
  *
@@ -2212,6 +2226,19 @@ class NotYetImplementedError extends Error {
2212
2226
  }
2213
2227
  }
2214
2228
 
2229
+ /**
2230
+ * Error thrown when a fetch request fails
2231
+ *
2232
+ * @public exported from `@promptbook/core`
2233
+ */
2234
+ class PromptbookFetchError extends Error {
2235
+ constructor(message) {
2236
+ super(message);
2237
+ this.name = 'PromptbookFetchError';
2238
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
2239
+ }
2240
+ }
2241
+
2215
2242
  /**
2216
2243
  * Index of all custom errors
2217
2244
  *
@@ -2249,6 +2276,8 @@ const COMMON_JAVASCRIPT_ERRORS = {
2249
2276
  TypeError,
2250
2277
  URIError,
2251
2278
  AggregateError,
2279
+ AuthenticationError,
2280
+ PromptbookFetchError,
2252
2281
  /*
2253
2282
  Note: Not widely supported
2254
2283
  > InternalError,
@@ -2310,6 +2339,7 @@ function assertsTaskSuccessful(executionResult) {
2310
2339
  const { isSuccessful, errors, warnings } = executionResult;
2311
2340
  for (const warning of warnings) {
2312
2341
  console.warn(warning.message);
2342
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2313
2343
  }
2314
2344
  if (isSuccessful === true) {
2315
2345
  return;
@@ -2447,6 +2477,10 @@ function serializeError(error) {
2447
2477
 
2448
2478
  Cannot serialize error with name "${name}"
2449
2479
 
2480
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2481
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2482
+
2483
+
2450
2484
  ${block(stack || message)}
2451
2485
 
2452
2486
  `));
@@ -2488,30 +2522,42 @@ async function forEachAsync(array, options, callbackfunction) {
2488
2522
  await Promise.all(tasks);
2489
2523
  }
2490
2524
 
2525
+ /**
2526
+ * Represents the uncertain value
2527
+ *
2528
+ * @public exported from `@promptbook/core`
2529
+ */
2530
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2531
+ /**
2532
+ * Represents the uncertain value
2533
+ *
2534
+ * @public exported from `@promptbook/core`
2535
+ */
2536
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2491
2537
  /**
2492
2538
  * Represents the usage with no resources consumed
2493
2539
  *
2494
2540
  * @public exported from `@promptbook/core`
2495
2541
  */
2496
2542
  const ZERO_USAGE = $deepFreeze({
2497
- price: { value: 0 },
2543
+ price: ZERO_VALUE,
2498
2544
  input: {
2499
- tokensCount: { value: 0 },
2500
- charactersCount: { value: 0 },
2501
- wordsCount: { value: 0 },
2502
- sentencesCount: { value: 0 },
2503
- linesCount: { value: 0 },
2504
- paragraphsCount: { value: 0 },
2505
- pagesCount: { value: 0 },
2545
+ tokensCount: ZERO_VALUE,
2546
+ charactersCount: ZERO_VALUE,
2547
+ wordsCount: ZERO_VALUE,
2548
+ sentencesCount: ZERO_VALUE,
2549
+ linesCount: ZERO_VALUE,
2550
+ paragraphsCount: ZERO_VALUE,
2551
+ pagesCount: ZERO_VALUE,
2506
2552
  },
2507
2553
  output: {
2508
- tokensCount: { value: 0 },
2509
- charactersCount: { value: 0 },
2510
- wordsCount: { value: 0 },
2511
- sentencesCount: { value: 0 },
2512
- linesCount: { value: 0 },
2513
- paragraphsCount: { value: 0 },
2514
- pagesCount: { value: 0 },
2554
+ tokensCount: ZERO_VALUE,
2555
+ charactersCount: ZERO_VALUE,
2556
+ wordsCount: ZERO_VALUE,
2557
+ sentencesCount: ZERO_VALUE,
2558
+ linesCount: ZERO_VALUE,
2559
+ paragraphsCount: ZERO_VALUE,
2560
+ pagesCount: ZERO_VALUE,
2515
2561
  },
2516
2562
  });
2517
2563
  /**
@@ -2520,24 +2566,24 @@ const ZERO_USAGE = $deepFreeze({
2520
2566
  * @public exported from `@promptbook/core`
2521
2567
  */
2522
2568
  $deepFreeze({
2523
- price: { value: 0, isUncertain: true },
2569
+ price: UNCERTAIN_ZERO_VALUE,
2524
2570
  input: {
2525
- tokensCount: { value: 0, isUncertain: true },
2526
- charactersCount: { value: 0, isUncertain: true },
2527
- wordsCount: { value: 0, isUncertain: true },
2528
- sentencesCount: { value: 0, isUncertain: true },
2529
- linesCount: { value: 0, isUncertain: true },
2530
- paragraphsCount: { value: 0, isUncertain: true },
2531
- pagesCount: { value: 0, isUncertain: true },
2571
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2572
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2573
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2574
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2575
+ linesCount: UNCERTAIN_ZERO_VALUE,
2576
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2577
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2532
2578
  },
2533
2579
  output: {
2534
- tokensCount: { value: 0, isUncertain: true },
2535
- charactersCount: { value: 0, isUncertain: true },
2536
- wordsCount: { value: 0, isUncertain: true },
2537
- sentencesCount: { value: 0, isUncertain: true },
2538
- linesCount: { value: 0, isUncertain: true },
2539
- paragraphsCount: { value: 0, isUncertain: true },
2540
- pagesCount: { value: 0, isUncertain: true },
2580
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2581
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2582
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2583
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2584
+ linesCount: UNCERTAIN_ZERO_VALUE,
2585
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2586
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2541
2587
  },
2542
2588
  });
2543
2589
  /**
@@ -2825,6 +2871,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2825
2871
  `);
2826
2872
  // TODO: [🟥] Detect browser / node and make it colorfull
2827
2873
  console.warn(warningMessage);
2874
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2828
2875
  /*
2829
2876
  return {
2830
2877
  async listModels() {
@@ -3210,17 +3257,24 @@ function mimeTypeToExtension(value) {
3210
3257
  /**
3211
3258
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3212
3259
  *
3213
- * @private as default `fetch` function used in Promptbook scrapers
3260
+ * @public exported from `@promptbook/core`
3214
3261
  */
3215
- const scraperFetch = async (url, init) => {
3262
+ const promptbookFetch = async (urlOrRequest, init) => {
3216
3263
  try {
3217
- return await fetch(url, init);
3264
+ return await fetch(urlOrRequest, init);
3218
3265
  }
3219
3266
  catch (error) {
3220
3267
  if (!(error instanceof Error)) {
3221
3268
  throw error;
3222
3269
  }
3223
- throw new KnowledgeScrapeError(spaceTrim((block) => `
3270
+ let url;
3271
+ if (typeof urlOrRequest === 'string') {
3272
+ url = urlOrRequest;
3273
+ }
3274
+ else if (urlOrRequest instanceof Request) {
3275
+ url = urlOrRequest.url;
3276
+ }
3277
+ throw new PromptbookFetchError(spaceTrim((block) => `
3224
3278
  Can not fetch "${url}"
3225
3279
 
3226
3280
  Fetch error:
@@ -3241,7 +3295,7 @@ const scraperFetch = async (url, init) => {
3241
3295
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3242
3296
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
3243
3297
  var _a;
3244
- const { fetch = scraperFetch } = tools;
3298
+ const { fetch = promptbookFetch } = tools;
3245
3299
  const { knowledgeSourceContent } = knowledgeSource;
3246
3300
  let { name } = knowledgeSource;
3247
3301
  const { rootDirname = null,
@@ -3382,63 +3436,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3382
3436
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3383
3437
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3384
3438
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3385
- let partialPieces = null;
3386
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3387
- const scrapers = arrayableToArray(tools.scrapers);
3388
- for (const scraper of scrapers) {
3389
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3390
- // <- TODO: [🦔] Implement mime-type wildcards
3391
- ) {
3392
- continue;
3393
- }
3394
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3395
- if (partialPiecesUnchecked !== null) {
3396
- partialPieces = [...partialPiecesUnchecked];
3397
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3398
- break;
3399
- }
3400
- console.warn(spaceTrim((block) => `
3401
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3439
+ try {
3440
+ let partialPieces = null;
3441
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3442
+ const scrapers = arrayableToArray(tools.scrapers);
3443
+ for (const scraper of scrapers) {
3444
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3445
+ // <- TODO: [🦔] Implement mime-type wildcards
3446
+ ) {
3447
+ continue;
3448
+ }
3449
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3450
+ if (partialPiecesUnchecked !== null) {
3451
+ partialPieces = [...partialPiecesUnchecked];
3452
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3453
+ break;
3454
+ }
3455
+ console.warn(spaceTrim((block) => `
3456
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3402
3457
 
3403
- The source:
3404
- ${block(knowledgeSource.knowledgeSourceContent
3405
- .split('\n')
3406
- .map((line) => `> ${line}`)
3407
- .join('\n'))}
3458
+ The source:
3459
+ ${block(knowledgeSource.knowledgeSourceContent
3460
+ .split('\n')
3461
+ .map((line) => `> ${line}`)
3462
+ .join('\n'))}
3408
3463
 
3409
- ${block($registeredScrapersMessage(scrapers))}
3464
+ ${block($registeredScrapersMessage(scrapers))}
3410
3465
 
3411
3466
 
3412
- `));
3413
- }
3414
- if (partialPieces === null) {
3415
- throw new KnowledgeScrapeError(spaceTrim((block) => `
3416
- Cannot scrape knowledge
3467
+ `));
3468
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3469
+ }
3470
+ if (partialPieces === null) {
3471
+ throw new KnowledgeScrapeError(spaceTrim((block) => `
3472
+ Cannot scrape knowledge
3417
3473
 
3418
- The source:
3419
- > ${block(knowledgeSource.knowledgeSourceContent
3420
- .split('\n')
3421
- .map((line) => `> ${line}`)
3422
- .join('\n'))}
3474
+ The source:
3475
+ > ${block(knowledgeSource.knowledgeSourceContent
3476
+ .split('\n')
3477
+ .map((line) => `> ${line}`)
3478
+ .join('\n'))}
3423
3479
 
3424
- No scraper found for the mime type "${sourceHandler.mimeType}"
3480
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3425
3481
 
3426
- ${block($registeredScrapersMessage(scrapers))}
3482
+ ${block($registeredScrapersMessage(scrapers))}
3427
3483
 
3428
3484
 
3429
- `));
3485
+ `));
3486
+ }
3487
+ const pieces = partialPieces.map((partialPiece) => ({
3488
+ ...partialPiece,
3489
+ sources: [
3490
+ {
3491
+ name: knowledgeSource.name,
3492
+ // line, column <- TODO: [☀]
3493
+ // <- TODO: [❎]
3494
+ },
3495
+ ],
3496
+ }));
3497
+ knowledgePreparedUnflatten[index] = pieces;
3498
+ }
3499
+ catch (error) {
3500
+ if (!(error instanceof Error)) {
3501
+ throw error;
3502
+ }
3503
+ console.warn(error);
3504
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3430
3505
  }
3431
- const pieces = partialPieces.map((partialPiece) => ({
3432
- ...partialPiece,
3433
- sources: [
3434
- {
3435
- name: knowledgeSource.name,
3436
- // line, column <- TODO: [☀]
3437
- // <- TODO: [❎]
3438
- },
3439
- ],
3440
- }));
3441
- knowledgePreparedUnflatten[index] = pieces;
3442
3506
  });
3443
3507
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3444
3508
  return knowledgePrepared;
@@ -3856,7 +3920,7 @@ function extractParameterNamesFromTask(task) {
3856
3920
  if (parameterNames.has(subparameterName)) {
3857
3921
  parameterNames.delete(subparameterName);
3858
3922
  parameterNames.add(foreach.parameterName);
3859
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
3923
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3860
3924
  }
3861
3925
  }
3862
3926
  }
@@ -5452,6 +5516,7 @@ function createPipelineExecutor(options) {
5452
5516
 
5453
5517
  @see more at https://ptbk.io/prepare-pipeline
5454
5518
  `));
5519
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5455
5520
  }
5456
5521
  let runCount = 0;
5457
5522
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {