@promptbook/pdf 0.89.0-3 → 0.89.0-31

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 (50) hide show
  1. package/README.md +9 -7
  2. package/esm/index.es.js +122 -39
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/servers.d.ts +40 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +20 -8
  6. package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
  7. package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
  8. package/esm/typings/src/_packages/types.index.d.ts +24 -12
  9. package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
  10. package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
  11. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +28 -0
  12. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  13. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
  14. package/esm/typings/src/config.d.ts +24 -26
  15. package/esm/typings/src/errors/0-index.d.ts +9 -0
  16. package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
  17. package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
  18. package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
  19. package/esm/typings/src/errors/WrappedError.d.ts +10 -0
  20. package/esm/typings/src/errors/assertsError.d.ts +11 -0
  21. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  22. package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
  23. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
  24. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
  25. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +45 -1
  26. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
  27. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  28. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
  29. package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
  30. package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
  31. package/esm/typings/src/remote-server/openapi.d.ts +187 -0
  32. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
  33. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  34. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  35. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  36. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  37. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  38. package/esm/typings/src/remote-server/startRemoteServer.d.ts +3 -4
  39. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
  40. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +84 -9
  41. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  42. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  43. package/esm/typings/src/types/typeAliases.d.ts +19 -0
  44. package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
  45. package/package.json +9 -5
  46. package/umd/index.umd.js +122 -39
  47. package/umd/index.umd.js.map +1 -1
  48. package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
  49. package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
  50. package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/README.md CHANGED
@@ -246,6 +246,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
246
246
 
247
247
 
248
248
 
249
+ ## 🔒 Security
250
+
251
+ For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
252
+
249
253
  ## 📦 Packages _(for developers)_
250
254
 
251
255
  This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -302,7 +306,7 @@ The following glossary is used to clarify certain concepts:
302
306
  ### General LLM / AI terms
303
307
 
304
308
  - **Prompt drift** is a phenomenon where the AI model starts to generate outputs that are not aligned with the original prompt. This can happen due to the model's training data, the prompt's wording, or the model's architecture.
305
- - **Pipeline, workflow or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.
309
+ - [**Pipeline, workflow scenario or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.](https://github.com/webgptorg/promptbook/discussions/88)
306
310
  - **Fine-tuning** is a process where a pre-trained AI model is further trained on a specific dataset to improve its performance on a specific task.
307
311
  - **Zero-shot learning** is a machine learning paradigm where a model is trained to perform a task without any labeled examples. Instead, the model is provided with a description of the task and is expected to generate the correct output.
308
312
  - **Few-shot learning** is a machine learning paradigm where a model is trained to perform a task with only a few labeled examples. This is in contrast to traditional machine learning, where models are trained on large datasets.
@@ -310,10 +314,6 @@ The following glossary is used to clarify certain concepts:
310
314
  - **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
311
315
  - **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
312
316
 
313
-
314
-
315
-
316
-
317
317
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
318
318
 
319
319
 
@@ -427,6 +427,8 @@ See [TODO.md](./TODO.md)
427
427
 
428
428
  ## 🖋️ Contributing
429
429
 
430
- We are open to pull requests, feedback, and suggestions.
430
+ You can also ⭐ star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).We are open to [pull requests, feedback, and suggestions](./CONTRIBUTING.md).
431
+
432
+ ## 📞 Support
431
433
 
432
- You can also star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).
434
+ If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
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-3';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-31';
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
@@ -89,6 +89,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
89
89
  * @public exported from `@promptbook/core`
90
90
  */
91
91
  const ADMIN_GITHUB_NAME = 'hejny';
92
+ // <- TODO: [🐊] Pick the best claim
92
93
  /**
93
94
  * When the title is not provided, the default title is used
94
95
  *
@@ -121,6 +122,7 @@ const VALUE_STRINGS = {
121
122
  infinity: '(infinity; ∞)',
122
123
  negativeInfinity: '(negative infinity; -∞)',
123
124
  unserializable: '(unserializable value)',
125
+ circular: '(circular JSON)',
124
126
  };
125
127
  /**
126
128
  * Small number limit
@@ -160,6 +162,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
160
162
  */
161
163
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
162
164
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
165
+ // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
163
166
  /**
164
167
  * Where to store the temporary downloads
165
168
  *
@@ -211,7 +214,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
211
214
  true);
212
215
  /**
213
216
  * Note: [💞] Ignore a discrepancy between file name and entity name
214
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
217
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
215
218
  */
216
219
 
217
220
  /**
@@ -890,6 +893,54 @@ class ParseError extends Error {
890
893
  * TODO: Maybe split `ParseError` and `ApplyError`
891
894
  */
892
895
 
896
+ /**
897
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
898
+ *
899
+ * @public exported from `@promptbook/core`
900
+ */
901
+ class WrappedError extends Error {
902
+ constructor(whatWasThrown) {
903
+ const tag = `[🤮]`;
904
+ console.error(tag, whatWasThrown);
905
+ super(spaceTrim$1(`
906
+ Non-Error object was thrown
907
+
908
+ Note: Look for ${tag} in the console for more details
909
+ Please report issue on ${ADMIN_EMAIL}
910
+ `));
911
+ this.name = 'WrappedError';
912
+ Object.setPrototypeOf(this, WrappedError.prototype);
913
+ }
914
+ }
915
+
916
+ /**
917
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
918
+ *
919
+ * @param whatWasThrown Any object that was thrown
920
+ * @returns Nothing if the error is an instance of `Error`
921
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
922
+ *
923
+ * @private within the repository
924
+ */
925
+ function assertsError(whatWasThrown) {
926
+ // Case 1: Handle error which was rethrown as `WrappedError`
927
+ if (whatWasThrown instanceof WrappedError) {
928
+ const wrappedError = whatWasThrown;
929
+ throw wrappedError;
930
+ }
931
+ // Case 2: Handle unexpected errors
932
+ if (whatWasThrown instanceof UnexpectedError) {
933
+ const unexpectedError = whatWasThrown;
934
+ throw unexpectedError;
935
+ }
936
+ // Case 3: Handle standard errors - keep them up to consumer
937
+ if (whatWasThrown instanceof Error) {
938
+ return;
939
+ }
940
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
941
+ throw new WrappedError(whatWasThrown);
942
+ }
943
+
893
944
  /**
894
945
  * Function isValidJsonString will tell you if the string is valid JSON or not
895
946
  *
@@ -901,9 +952,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
901
952
  return true;
902
953
  }
903
954
  catch (error) {
904
- if (!(error instanceof Error)) {
905
- throw error;
906
- }
955
+ assertsError(error);
907
956
  if (error.message.includes('Unexpected token')) {
908
957
  return false;
909
958
  }
@@ -1256,9 +1305,7 @@ function checkSerializableAsJson(options) {
1256
1305
  JSON.stringify(value); // <- TODO: [0]
1257
1306
  }
1258
1307
  catch (error) {
1259
- if (!(error instanceof Error)) {
1260
- throw error;
1261
- }
1308
+ assertsError(error);
1262
1309
  throw new UnexpectedError(spaceTrim((block) => `
1263
1310
  \`${name}\` is not serializable
1264
1311
 
@@ -2047,7 +2094,7 @@ class PipelineExecutionError extends Error {
2047
2094
  }
2048
2095
  }
2049
2096
  /**
2050
- * TODO: !!!!!! Add id to all errors
2097
+ * TODO: [🧠][🌂] Add id to all errors
2051
2098
  */
2052
2099
 
2053
2100
  /**
@@ -2147,6 +2194,19 @@ class CsvFormatError extends AbstractFormatError {
2147
2194
  }
2148
2195
  }
2149
2196
 
2197
+ /**
2198
+ * AuthenticationError is thrown from login function which is dependency of remote server
2199
+ *
2200
+ * @public exported from `@promptbook/core`
2201
+ */
2202
+ class AuthenticationError extends Error {
2203
+ constructor(message) {
2204
+ super(message);
2205
+ this.name = 'AuthenticationError';
2206
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
2207
+ }
2208
+ }
2209
+
2150
2210
  /**
2151
2211
  * This error indicates that the pipeline collection cannot be propperly loaded
2152
2212
  *
@@ -2212,6 +2272,19 @@ class NotYetImplementedError extends Error {
2212
2272
  }
2213
2273
  }
2214
2274
 
2275
+ /**
2276
+ * Error thrown when a fetch request fails
2277
+ *
2278
+ * @public exported from `@promptbook/core`
2279
+ */
2280
+ class PromptbookFetchError extends Error {
2281
+ constructor(message) {
2282
+ super(message);
2283
+ this.name = 'PromptbookFetchError';
2284
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
2285
+ }
2286
+ }
2287
+
2215
2288
  /**
2216
2289
  * Index of all custom errors
2217
2290
  *
@@ -2232,7 +2305,10 @@ const PROMPTBOOK_ERRORS = {
2232
2305
  PipelineExecutionError,
2233
2306
  PipelineLogicError,
2234
2307
  PipelineUrlError,
2308
+ AuthenticationError,
2309
+ PromptbookFetchError,
2235
2310
  UnexpectedError,
2311
+ WrappedError,
2236
2312
  // TODO: [🪑]> VersionMismatchError,
2237
2313
  };
2238
2314
  /**
@@ -2371,8 +2447,8 @@ function createTask(options) {
2371
2447
  updatedAt = new Date();
2372
2448
  errors.push(...executionResult.errors);
2373
2449
  warnings.push(...executionResult.warnings);
2374
- // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2375
- // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2450
+ // <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
2451
+ // TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2376
2452
  // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2377
2453
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2378
2454
  assertsTaskSuccessful(executionResult);
@@ -2382,6 +2458,7 @@ function createTask(options) {
2382
2458
  partialResultSubject.next(executionResult);
2383
2459
  }
2384
2460
  catch (error) {
2461
+ assertsError(error);
2385
2462
  status = 'ERROR';
2386
2463
  errors.push(error);
2387
2464
  partialResultSubject.error(error);
@@ -2448,6 +2525,10 @@ function serializeError(error) {
2448
2525
 
2449
2526
  Cannot serialize error with name "${name}"
2450
2527
 
2528
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2529
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2530
+
2531
+
2451
2532
  ${block(stack || message)}
2452
2533
 
2453
2534
  `));
@@ -2769,14 +2850,15 @@ class MultipleLlmExecutionTools {
2769
2850
  }
2770
2851
  }
2771
2852
  catch (error) {
2772
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
2853
+ assertsError(error);
2854
+ if (error instanceof UnexpectedError) {
2773
2855
  throw error;
2774
2856
  }
2775
2857
  errors.push({ llmExecutionTools, error });
2776
2858
  }
2777
2859
  }
2778
2860
  if (errors.length === 1) {
2779
- throw errors[0];
2861
+ throw errors[0].error;
2780
2862
  }
2781
2863
  else if (errors.length > 1) {
2782
2864
  throw new PipelineExecutionError(
@@ -3224,17 +3306,22 @@ function mimeTypeToExtension(value) {
3224
3306
  /**
3225
3307
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3226
3308
  *
3227
- * @private as default `fetch` function used in Promptbook scrapers
3309
+ * @public exported from `@promptbook/core`
3228
3310
  */
3229
- const scraperFetch = async (url, init) => {
3311
+ const promptbookFetch = async (urlOrRequest, init) => {
3230
3312
  try {
3231
- return await fetch(url, init);
3313
+ return await fetch(urlOrRequest, init);
3232
3314
  }
3233
3315
  catch (error) {
3234
- if (!(error instanceof Error)) {
3235
- throw error;
3316
+ assertsError(error);
3317
+ let url;
3318
+ if (typeof urlOrRequest === 'string') {
3319
+ url = urlOrRequest;
3320
+ }
3321
+ else if (urlOrRequest instanceof Request) {
3322
+ url = urlOrRequest.url;
3236
3323
  }
3237
- throw new KnowledgeScrapeError(spaceTrim((block) => `
3324
+ throw new PromptbookFetchError(spaceTrim((block) => `
3238
3325
  Can not fetch "${url}"
3239
3326
 
3240
3327
  Fetch error:
@@ -3255,7 +3342,7 @@ const scraperFetch = async (url, init) => {
3255
3342
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3256
3343
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
3257
3344
  var _a;
3258
- const { fetch = scraperFetch } = tools;
3345
+ const { fetch = promptbookFetch } = tools;
3259
3346
  const { knowledgeSourceContent } = knowledgeSource;
3260
3347
  let { name } = knowledgeSource;
3261
3348
  const { rootDirname = null,
@@ -3457,9 +3544,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3457
3544
  knowledgePreparedUnflatten[index] = pieces;
3458
3545
  }
3459
3546
  catch (error) {
3460
- if (!(error instanceof Error)) {
3461
- throw error;
3462
- }
3547
+ assertsError(error);
3463
3548
  console.warn(error);
3464
3549
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3465
3550
  }
@@ -3751,13 +3836,19 @@ function valueToString(value) {
3751
3836
  return value.toISOString();
3752
3837
  }
3753
3838
  else {
3754
- return JSON.stringify(value);
3839
+ try {
3840
+ return JSON.stringify(value);
3841
+ }
3842
+ catch (error) {
3843
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
3844
+ return VALUE_STRINGS.circular;
3845
+ }
3846
+ throw error;
3847
+ }
3755
3848
  }
3756
3849
  }
3757
3850
  catch (error) {
3758
- if (!(error instanceof Error)) {
3759
- throw error;
3760
- }
3851
+ assertsError(error);
3761
3852
  console.error(error);
3762
3853
  return VALUE_STRINGS.unserializable;
3763
3854
  }
@@ -3814,9 +3905,7 @@ function extractVariablesFromJavascript(script) {
3814
3905
  }
3815
3906
  }
3816
3907
  catch (error) {
3817
- if (!(error instanceof Error)) {
3818
- throw error;
3819
- }
3908
+ assertsError(error);
3820
3909
  throw new ParseError(spaceTrim$1((block) => `
3821
3910
  Can not extract variables from the script
3822
3911
  ${block(error.stack || error.message)}
@@ -4681,9 +4770,7 @@ async function executeAttempts(options) {
4681
4770
  break scripts;
4682
4771
  }
4683
4772
  catch (error) {
4684
- if (!(error instanceof Error)) {
4685
- throw error;
4686
- }
4773
+ assertsError(error);
4687
4774
  if (error instanceof UnexpectedError) {
4688
4775
  throw error;
4689
4776
  }
@@ -4753,9 +4840,7 @@ async function executeAttempts(options) {
4753
4840
  break scripts;
4754
4841
  }
4755
4842
  catch (error) {
4756
- if (!(error instanceof Error)) {
4757
- throw error;
4758
- }
4843
+ assertsError(error);
4759
4844
  if (error instanceof UnexpectedError) {
4760
4845
  throw error;
4761
4846
  }
@@ -5376,9 +5461,7 @@ async function executePipeline(options) {
5376
5461
  await Promise.all(resolving);
5377
5462
  }
5378
5463
  catch (error /* <- Note: [3] */) {
5379
- if (!(error instanceof Error)) {
5380
- throw error;
5381
- }
5464
+ assertsError(error);
5382
5465
  // Note: No need to rethrow UnexpectedError
5383
5466
  // if (error instanceof UnexpectedError) {
5384
5467
  // Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹‍♂️]