@promptbook/pdf 0.89.0-9 → 0.89.0

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 (40) hide show
  1. package/README.md +9 -11
  2. package/esm/index.es.js +131 -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 +8 -4
  6. package/esm/typings/src/_packages/types.index.d.ts +18 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  8. package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
  9. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
  10. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  11. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
  12. package/esm/typings/src/config.d.ts +10 -19
  13. package/esm/typings/src/errors/0-index.d.ts +7 -4
  14. package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
  15. package/esm/typings/src/errors/WrappedError.d.ts +10 -0
  16. package/esm/typings/src/errors/assertsError.d.ts +11 -0
  17. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  18. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
  19. package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
  20. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
  21. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
  22. package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
  23. package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts → $provideEnvFilename.d.ts} +2 -2
  24. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  25. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  26. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
  27. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  28. package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
  29. package/esm/typings/src/remote-server/openapi.d.ts +187 -0
  30. package/esm/typings/src/remote-server/socket-types/_subtypes/Identification.d.ts +7 -1
  31. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  32. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  33. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  34. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
  35. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  36. package/esm/typings/src/types/typeAliases.d.ts +26 -0
  37. package/package.json +9 -5
  38. package/umd/index.umd.js +131 -39
  39. package/umd/index.umd.js.map +1 -1
  40. package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
package/README.md CHANGED
@@ -23,10 +23,6 @@
23
23
 
24
24
 
25
25
 
26
- <blockquote style="color: #ff8811">
27
- <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
- </blockquote>
29
-
30
26
  ## 📦 Package `@promptbook/pdf`
31
27
 
32
28
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -246,6 +242,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
246
242
 
247
243
 
248
244
 
245
+ ## 🔒 Security
246
+
247
+ For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
248
+
249
249
  ## 📦 Packages _(for developers)_
250
250
 
251
251
  This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -302,7 +302,7 @@ The following glossary is used to clarify certain concepts:
302
302
  ### General LLM / AI terms
303
303
 
304
304
  - **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.
305
+ - [**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
306
  - **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
307
  - **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
308
  - **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 +310,6 @@ The following glossary is used to clarify certain concepts:
310
310
  - **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
311
  - **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
312
 
313
-
314
-
315
-
316
-
317
313
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
318
314
 
319
315
 
@@ -427,6 +423,8 @@ See [TODO.md](./TODO.md)
427
423
 
428
424
  ## 🖋️ Contributing
429
425
 
430
- We are open to pull requests, feedback, and suggestions.
426
+ 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).
427
+
428
+ ## 📞 Support
431
429
 
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/).
430
+ 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-9';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0';
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,7 +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`
163
- // TODO: !!!!!! Just .promptbook dir, hardocode others
165
+ // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
164
166
  /**
165
167
  * Where to store the temporary downloads
166
168
  *
@@ -891,9 +893,60 @@ class ParseError extends Error {
891
893
  * TODO: Maybe split `ParseError` and `ApplyError`
892
894
  */
893
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
+
894
944
  /**
895
945
  * Function isValidJsonString will tell you if the string is valid JSON or not
896
946
  *
947
+ * @param value The string to check
948
+ * @returns True if the string is a valid JSON string, false otherwise
949
+ *
897
950
  * @public exported from `@promptbook/utils`
898
951
  */
899
952
  function isValidJsonString(value /* <- [👨‍⚖️] */) {
@@ -902,9 +955,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
902
955
  return true;
903
956
  }
904
957
  catch (error) {
905
- if (!(error instanceof Error)) {
906
- throw error;
907
- }
958
+ assertsError(error);
908
959
  if (error.message.includes('Unexpected token')) {
909
960
  return false;
910
961
  }
@@ -1257,9 +1308,7 @@ function checkSerializableAsJson(options) {
1257
1308
  JSON.stringify(value); // <- TODO: [0]
1258
1309
  }
1259
1310
  catch (error) {
1260
- if (!(error instanceof Error)) {
1261
- throw error;
1262
- }
1311
+ assertsError(error);
1263
1312
  throw new UnexpectedError(spaceTrim((block) => `
1264
1313
  \`${name}\` is not serializable
1265
1314
 
@@ -2048,7 +2097,7 @@ class PipelineExecutionError extends Error {
2048
2097
  }
2049
2098
  }
2050
2099
  /**
2051
- * TODO: !!!!!! Add id to all errors
2100
+ * TODO: [🧠][🌂] Add id to all errors
2052
2101
  */
2053
2102
 
2054
2103
  /**
@@ -2259,7 +2308,10 @@ const PROMPTBOOK_ERRORS = {
2259
2308
  PipelineExecutionError,
2260
2309
  PipelineLogicError,
2261
2310
  PipelineUrlError,
2311
+ AuthenticationError,
2312
+ PromptbookFetchError,
2262
2313
  UnexpectedError,
2314
+ WrappedError,
2263
2315
  // TODO: [🪑]> VersionMismatchError,
2264
2316
  };
2265
2317
  /**
@@ -2276,8 +2328,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
2276
2328
  TypeError,
2277
2329
  URIError,
2278
2330
  AggregateError,
2279
- AuthenticationError,
2280
- PromptbookFetchError,
2281
2331
  /*
2282
2332
  Note: Not widely supported
2283
2333
  > InternalError,
@@ -2400,8 +2450,8 @@ function createTask(options) {
2400
2450
  updatedAt = new Date();
2401
2451
  errors.push(...executionResult.errors);
2402
2452
  warnings.push(...executionResult.warnings);
2403
- // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2404
- // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2453
+ // <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
2454
+ // TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2405
2455
  // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2406
2456
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2407
2457
  assertsTaskSuccessful(executionResult);
@@ -2411,6 +2461,7 @@ function createTask(options) {
2411
2461
  partialResultSubject.next(executionResult);
2412
2462
  }
2413
2463
  catch (error) {
2464
+ assertsError(error);
2414
2465
  status = 'ERROR';
2415
2466
  errors.push(error);
2416
2467
  partialResultSubject.error(error);
@@ -2802,14 +2853,15 @@ class MultipleLlmExecutionTools {
2802
2853
  }
2803
2854
  }
2804
2855
  catch (error) {
2805
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
2856
+ assertsError(error);
2857
+ if (error instanceof UnexpectedError) {
2806
2858
  throw error;
2807
2859
  }
2808
2860
  errors.push({ llmExecutionTools, error });
2809
2861
  }
2810
2862
  }
2811
2863
  if (errors.length === 1) {
2812
- throw errors[0];
2864
+ throw errors[0].error;
2813
2865
  }
2814
2866
  else if (errors.length > 1) {
2815
2867
  throw new PipelineExecutionError(
@@ -3264,9 +3316,7 @@ const promptbookFetch = async (urlOrRequest, init) => {
3264
3316
  return await fetch(urlOrRequest, init);
3265
3317
  }
3266
3318
  catch (error) {
3267
- if (!(error instanceof Error)) {
3268
- throw error;
3269
- }
3319
+ assertsError(error);
3270
3320
  let url;
3271
3321
  if (typeof urlOrRequest === 'string') {
3272
3322
  url = urlOrRequest;
@@ -3497,9 +3547,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3497
3547
  knowledgePreparedUnflatten[index] = pieces;
3498
3548
  }
3499
3549
  catch (error) {
3500
- if (!(error instanceof Error)) {
3501
- throw error;
3502
- }
3550
+ assertsError(error);
3503
3551
  console.warn(error);
3504
3552
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3505
3553
  }
@@ -3791,13 +3839,19 @@ function valueToString(value) {
3791
3839
  return value.toISOString();
3792
3840
  }
3793
3841
  else {
3794
- return JSON.stringify(value);
3842
+ try {
3843
+ return JSON.stringify(value);
3844
+ }
3845
+ catch (error) {
3846
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
3847
+ return VALUE_STRINGS.circular;
3848
+ }
3849
+ throw error;
3850
+ }
3795
3851
  }
3796
3852
  }
3797
3853
  catch (error) {
3798
- if (!(error instanceof Error)) {
3799
- throw error;
3800
- }
3854
+ assertsError(error);
3801
3855
  console.error(error);
3802
3856
  return VALUE_STRINGS.unserializable;
3803
3857
  }
@@ -3854,9 +3908,7 @@ function extractVariablesFromJavascript(script) {
3854
3908
  }
3855
3909
  }
3856
3910
  catch (error) {
3857
- if (!(error instanceof Error)) {
3858
- throw error;
3859
- }
3911
+ assertsError(error);
3860
3912
  throw new ParseError(spaceTrim$1((block) => `
3861
3913
  Can not extract variables from the script
3862
3914
  ${block(error.stack || error.message)}
@@ -3975,6 +4027,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
3975
4027
  // encoding: 'utf-8',
3976
4028
  });
3977
4029
 
4030
+ /**
4031
+ * Function to check if a string is valid CSV
4032
+ *
4033
+ * @param value The string to check
4034
+ * @returns True if the string is a valid CSV string, false otherwise
4035
+ *
4036
+ * @public exported from `@promptbook/utils`
4037
+ */
4038
+ function isValidCsvString(value) {
4039
+ try {
4040
+ // A simple check for CSV format: at least one comma and no invalid characters
4041
+ if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
4042
+ return true;
4043
+ }
4044
+ return false;
4045
+ }
4046
+ catch (error) {
4047
+ assertsError(error);
4048
+ return false;
4049
+ }
4050
+ }
4051
+
3978
4052
  /**
3979
4053
  * Definition for CSV spreadsheet
3980
4054
  *
@@ -3985,7 +4059,7 @@ const CsvFormatDefinition = {
3985
4059
  formatName: 'CSV',
3986
4060
  aliases: ['SPREADSHEET', 'TABLE'],
3987
4061
  isValid(value, settings, schema) {
3988
- return true;
4062
+ return isValidCsvString(value);
3989
4063
  },
3990
4064
  canBeValid(partialValue, settings, schema) {
3991
4065
  return true;
@@ -4139,6 +4213,30 @@ const TextFormatDefinition = {
4139
4213
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
4140
4214
  */
4141
4215
 
4216
+ /**
4217
+ * Function to check if a string is valid XML
4218
+ *
4219
+ * @param value
4220
+ * @returns True if the string is a valid XML string, false otherwise
4221
+ *
4222
+ * @public exported from `@promptbook/utils`
4223
+ */
4224
+ function isValidXmlString(value) {
4225
+ try {
4226
+ const parser = new DOMParser();
4227
+ const parsedDocument = parser.parseFromString(value, 'application/xml');
4228
+ const parserError = parsedDocument.getElementsByTagName('parsererror');
4229
+ if (parserError.length > 0) {
4230
+ return false;
4231
+ }
4232
+ return true;
4233
+ }
4234
+ catch (error) {
4235
+ assertsError(error);
4236
+ return false;
4237
+ }
4238
+ }
4239
+
4142
4240
  /**
4143
4241
  * Definition for XML format
4144
4242
  *
@@ -4148,7 +4246,7 @@ const XmlFormatDefinition = {
4148
4246
  formatName: 'XML',
4149
4247
  mimeType: 'application/xml',
4150
4248
  isValid(value, settings, schema) {
4151
- return true;
4249
+ return isValidXmlString(value);
4152
4250
  },
4153
4251
  canBeValid(partialValue, settings, schema) {
4154
4252
  return true;
@@ -4721,9 +4819,7 @@ async function executeAttempts(options) {
4721
4819
  break scripts;
4722
4820
  }
4723
4821
  catch (error) {
4724
- if (!(error instanceof Error)) {
4725
- throw error;
4726
- }
4822
+ assertsError(error);
4727
4823
  if (error instanceof UnexpectedError) {
4728
4824
  throw error;
4729
4825
  }
@@ -4793,9 +4889,7 @@ async function executeAttempts(options) {
4793
4889
  break scripts;
4794
4890
  }
4795
4891
  catch (error) {
4796
- if (!(error instanceof Error)) {
4797
- throw error;
4798
- }
4892
+ assertsError(error);
4799
4893
  if (error instanceof UnexpectedError) {
4800
4894
  throw error;
4801
4895
  }
@@ -5416,9 +5510,7 @@ async function executePipeline(options) {
5416
5510
  await Promise.all(resolving);
5417
5511
  }
5418
5512
  catch (error /* <- Note: [3] */) {
5419
- if (!(error instanceof Error)) {
5420
- throw error;
5421
- }
5513
+ assertsError(error);
5422
5514
  // Note: No need to rethrow UnexpectedError
5423
5515
  // if (error instanceof UnexpectedError) {
5424
5516
  // Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹‍♂️]