@promptbook/website-crawler 0.89.0-9 โ†’ 0.92.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 (41) hide show
  1. package/README.md +9 -7
  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 +10 -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/filterModels.d.ts +15 -0
  24. package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts โ†’ $provideEnvFilename.d.ts} +2 -2
  25. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  26. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  27. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
  28. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  29. package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
  30. package/esm/typings/src/remote-server/openapi.d.ts +187 -0
  31. package/esm/typings/src/remote-server/socket-types/_subtypes/Identification.d.ts +7 -1
  32. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  33. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  34. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  35. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
  36. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  37. package/esm/typings/src/types/typeAliases.d.ts +26 -0
  38. package/package.json +9 -5
  39. package/umd/index.umd.js +131 -39
  40. package/umd/index.umd.js.map +1 -1
  41. package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
package/README.md CHANGED
@@ -244,6 +244,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
244
244
 
245
245
 
246
246
 
247
+ ## ๐Ÿ”’ Security
248
+
249
+ For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
250
+
247
251
  ## ๐Ÿ“ฆ Packages _(for developers)_
248
252
 
249
253
  This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -300,7 +304,7 @@ The following glossary is used to clarify certain concepts:
300
304
  ### General LLM / AI terms
301
305
 
302
306
  - **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.
303
- - **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.
307
+ - [**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)
304
308
  - **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.
305
309
  - **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.
306
310
  - **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.
@@ -308,10 +312,6 @@ The following glossary is used to clarify certain concepts:
308
312
  - **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.
309
313
  - **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.
310
314
 
311
-
312
-
313
-
314
-
315
315
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
316
316
 
317
317
 
@@ -425,6 +425,8 @@ See [TODO.md](./TODO.md)
425
425
 
426
426
  ## ๐Ÿ–‹๏ธ Contributing
427
427
 
428
- We are open to pull requests, feedback, and suggestions.
428
+ 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).
429
+
430
+ ## ๐Ÿ“ž Support
429
431
 
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/).
432
+ If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
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-9';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-3';
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
@@ -119,6 +119,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
119
119
  * @public exported from `@promptbook/core`
120
120
  */
121
121
  const ADMIN_GITHUB_NAME = 'hejny';
122
+ // <- TODO: [๐ŸŠ] Pick the best claim
122
123
  /**
123
124
  * When the title is not provided, the default title is used
124
125
  *
@@ -151,6 +152,7 @@ const VALUE_STRINGS = {
151
152
  infinity: '(infinity; โˆž)',
152
153
  negativeInfinity: '(negative infinity; -โˆž)',
153
154
  unserializable: '(unserializable value)',
155
+ circular: '(circular JSON)',
154
156
  };
155
157
  /**
156
158
  * Small number limit
@@ -190,7 +192,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
190
192
  */
191
193
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
192
194
  // <- TODO: [๐Ÿ•] Make also `BOOKS_DIRNAME_ALTERNATIVES`
193
- // TODO: !!!!!! Just .promptbook dir, hardocode others
195
+ // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
194
196
  /**
195
197
  * Where to store the temporary downloads
196
198
  *
@@ -1056,9 +1058,60 @@ class ParseError extends Error {
1056
1058
  * TODO: Maybe split `ParseError` and `ApplyError`
1057
1059
  */
1058
1060
 
1061
+ /**
1062
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
1063
+ *
1064
+ * @public exported from `@promptbook/core`
1065
+ */
1066
+ class WrappedError extends Error {
1067
+ constructor(whatWasThrown) {
1068
+ const tag = `[๐Ÿคฎ]`;
1069
+ console.error(tag, whatWasThrown);
1070
+ super(spaceTrim(`
1071
+ Non-Error object was thrown
1072
+
1073
+ Note: Look for ${tag} in the console for more details
1074
+ Please report issue on ${ADMIN_EMAIL}
1075
+ `));
1076
+ this.name = 'WrappedError';
1077
+ Object.setPrototypeOf(this, WrappedError.prototype);
1078
+ }
1079
+ }
1080
+
1081
+ /**
1082
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
1083
+ *
1084
+ * @param whatWasThrown Any object that was thrown
1085
+ * @returns Nothing if the error is an instance of `Error`
1086
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
1087
+ *
1088
+ * @private within the repository
1089
+ */
1090
+ function assertsError(whatWasThrown) {
1091
+ // Case 1: Handle error which was rethrown as `WrappedError`
1092
+ if (whatWasThrown instanceof WrappedError) {
1093
+ const wrappedError = whatWasThrown;
1094
+ throw wrappedError;
1095
+ }
1096
+ // Case 2: Handle unexpected errors
1097
+ if (whatWasThrown instanceof UnexpectedError) {
1098
+ const unexpectedError = whatWasThrown;
1099
+ throw unexpectedError;
1100
+ }
1101
+ // Case 3: Handle standard errors - keep them up to consumer
1102
+ if (whatWasThrown instanceof Error) {
1103
+ return;
1104
+ }
1105
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
1106
+ throw new WrappedError(whatWasThrown);
1107
+ }
1108
+
1059
1109
  /**
1060
1110
  * Function isValidJsonString will tell you if the string is valid JSON or not
1061
1111
  *
1112
+ * @param value The string to check
1113
+ * @returns True if the string is a valid JSON string, false otherwise
1114
+ *
1062
1115
  * @public exported from `@promptbook/utils`
1063
1116
  */
1064
1117
  function isValidJsonString(value /* <- [๐Ÿ‘จโ€โš–๏ธ] */) {
@@ -1067,9 +1120,7 @@ function isValidJsonString(value /* <- [๐Ÿ‘จโ€โš–๏ธ] */) {
1067
1120
  return true;
1068
1121
  }
1069
1122
  catch (error) {
1070
- if (!(error instanceof Error)) {
1071
- throw error;
1072
- }
1123
+ assertsError(error);
1073
1124
  if (error.message.includes('Unexpected token')) {
1074
1125
  return false;
1075
1126
  }
@@ -1395,9 +1446,7 @@ function checkSerializableAsJson(options) {
1395
1446
  JSON.stringify(value); // <- TODO: [0]
1396
1447
  }
1397
1448
  catch (error) {
1398
- if (!(error instanceof Error)) {
1399
- throw error;
1400
- }
1449
+ assertsError(error);
1401
1450
  throw new UnexpectedError(spaceTrim$1((block) => `
1402
1451
  \`${name}\` is not serializable
1403
1452
 
@@ -2186,7 +2235,7 @@ class PipelineExecutionError extends Error {
2186
2235
  }
2187
2236
  }
2188
2237
  /**
2189
- * TODO: !!!!!! Add id to all errors
2238
+ * TODO: [๐Ÿง ][๐ŸŒ‚] Add id to all errors
2190
2239
  */
2191
2240
 
2192
2241
  /**
@@ -2374,7 +2423,10 @@ const PROMPTBOOK_ERRORS = {
2374
2423
  PipelineExecutionError,
2375
2424
  PipelineLogicError,
2376
2425
  PipelineUrlError,
2426
+ AuthenticationError,
2427
+ PromptbookFetchError,
2377
2428
  UnexpectedError,
2429
+ WrappedError,
2378
2430
  // TODO: [๐Ÿช‘]> VersionMismatchError,
2379
2431
  };
2380
2432
  /**
@@ -2391,8 +2443,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
2391
2443
  TypeError,
2392
2444
  URIError,
2393
2445
  AggregateError,
2394
- AuthenticationError,
2395
- PromptbookFetchError,
2396
2446
  /*
2397
2447
  Note: Not widely supported
2398
2448
  > InternalError,
@@ -2515,8 +2565,8 @@ function createTask(options) {
2515
2565
  updatedAt = new Date();
2516
2566
  errors.push(...executionResult.errors);
2517
2567
  warnings.push(...executionResult.warnings);
2518
- // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2519
- // TODO: [๐Ÿง ] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2568
+ // <- TODO: [๐ŸŒ‚] Only unique errors and warnings should be added (or filtered)
2569
+ // TODO: [๐Ÿง ] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2520
2570
  // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2521
2571
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2522
2572
  assertsTaskSuccessful(executionResult);
@@ -2526,6 +2576,7 @@ function createTask(options) {
2526
2576
  partialResultSubject.next(executionResult);
2527
2577
  }
2528
2578
  catch (error) {
2579
+ assertsError(error);
2529
2580
  status = 'ERROR';
2530
2581
  errors.push(error);
2531
2582
  partialResultSubject.error(error);
@@ -2917,14 +2968,15 @@ class MultipleLlmExecutionTools {
2917
2968
  }
2918
2969
  }
2919
2970
  catch (error) {
2920
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
2971
+ assertsError(error);
2972
+ if (error instanceof UnexpectedError) {
2921
2973
  throw error;
2922
2974
  }
2923
2975
  errors.push({ llmExecutionTools, error });
2924
2976
  }
2925
2977
  }
2926
2978
  if (errors.length === 1) {
2927
- throw errors[0];
2979
+ throw errors[0].error;
2928
2980
  }
2929
2981
  else if (errors.length > 1) {
2930
2982
  throw new PipelineExecutionError(
@@ -3265,9 +3317,7 @@ const promptbookFetch = async (urlOrRequest, init) => {
3265
3317
  return await fetch(urlOrRequest, init);
3266
3318
  }
3267
3319
  catch (error) {
3268
- if (!(error instanceof Error)) {
3269
- throw error;
3270
- }
3320
+ assertsError(error);
3271
3321
  let url;
3272
3322
  if (typeof urlOrRequest === 'string') {
3273
3323
  url = urlOrRequest;
@@ -3498,9 +3548,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3498
3548
  knowledgePreparedUnflatten[index] = pieces;
3499
3549
  }
3500
3550
  catch (error) {
3501
- if (!(error instanceof Error)) {
3502
- throw error;
3503
- }
3551
+ assertsError(error);
3504
3552
  console.warn(error);
3505
3553
  // <- TODO: [๐Ÿฎ] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3506
3554
  }
@@ -3792,13 +3840,19 @@ function valueToString(value) {
3792
3840
  return value.toISOString();
3793
3841
  }
3794
3842
  else {
3795
- return JSON.stringify(value);
3843
+ try {
3844
+ return JSON.stringify(value);
3845
+ }
3846
+ catch (error) {
3847
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
3848
+ return VALUE_STRINGS.circular;
3849
+ }
3850
+ throw error;
3851
+ }
3796
3852
  }
3797
3853
  }
3798
3854
  catch (error) {
3799
- if (!(error instanceof Error)) {
3800
- throw error;
3801
- }
3855
+ assertsError(error);
3802
3856
  console.error(error);
3803
3857
  return VALUE_STRINGS.unserializable;
3804
3858
  }
@@ -3855,9 +3909,7 @@ function extractVariablesFromJavascript(script) {
3855
3909
  }
3856
3910
  }
3857
3911
  catch (error) {
3858
- if (!(error instanceof Error)) {
3859
- throw error;
3860
- }
3912
+ assertsError(error);
3861
3913
  throw new ParseError(spaceTrim((block) => `
3862
3914
  Can not extract variables from the script
3863
3915
  ${block(error.stack || error.message)}
@@ -3976,6 +4028,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
3976
4028
  // encoding: 'utf-8',
3977
4029
  });
3978
4030
 
4031
+ /**
4032
+ * Function to check if a string is valid CSV
4033
+ *
4034
+ * @param value The string to check
4035
+ * @returns True if the string is a valid CSV string, false otherwise
4036
+ *
4037
+ * @public exported from `@promptbook/utils`
4038
+ */
4039
+ function isValidCsvString(value) {
4040
+ try {
4041
+ // A simple check for CSV format: at least one comma and no invalid characters
4042
+ if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
4043
+ return true;
4044
+ }
4045
+ return false;
4046
+ }
4047
+ catch (error) {
4048
+ assertsError(error);
4049
+ return false;
4050
+ }
4051
+ }
4052
+
3979
4053
  /**
3980
4054
  * Definition for CSV spreadsheet
3981
4055
  *
@@ -3986,7 +4060,7 @@ const CsvFormatDefinition = {
3986
4060
  formatName: 'CSV',
3987
4061
  aliases: ['SPREADSHEET', 'TABLE'],
3988
4062
  isValid(value, settings, schema) {
3989
- return true;
4063
+ return isValidCsvString(value);
3990
4064
  },
3991
4065
  canBeValid(partialValue, settings, schema) {
3992
4066
  return true;
@@ -4140,6 +4214,30 @@ const TextFormatDefinition = {
4140
4214
  * TODO: [๐Ÿข] Allow to expect something inside each item of list and other formats
4141
4215
  */
4142
4216
 
4217
+ /**
4218
+ * Function to check if a string is valid XML
4219
+ *
4220
+ * @param value
4221
+ * @returns True if the string is a valid XML string, false otherwise
4222
+ *
4223
+ * @public exported from `@promptbook/utils`
4224
+ */
4225
+ function isValidXmlString(value) {
4226
+ try {
4227
+ const parser = new DOMParser();
4228
+ const parsedDocument = parser.parseFromString(value, 'application/xml');
4229
+ const parserError = parsedDocument.getElementsByTagName('parsererror');
4230
+ if (parserError.length > 0) {
4231
+ return false;
4232
+ }
4233
+ return true;
4234
+ }
4235
+ catch (error) {
4236
+ assertsError(error);
4237
+ return false;
4238
+ }
4239
+ }
4240
+
4143
4241
  /**
4144
4242
  * Definition for XML format
4145
4243
  *
@@ -4149,7 +4247,7 @@ const XmlFormatDefinition = {
4149
4247
  formatName: 'XML',
4150
4248
  mimeType: 'application/xml',
4151
4249
  isValid(value, settings, schema) {
4152
- return true;
4250
+ return isValidXmlString(value);
4153
4251
  },
4154
4252
  canBeValid(partialValue, settings, schema) {
4155
4253
  return true;
@@ -4722,9 +4820,7 @@ async function executeAttempts(options) {
4722
4820
  break scripts;
4723
4821
  }
4724
4822
  catch (error) {
4725
- if (!(error instanceof Error)) {
4726
- throw error;
4727
- }
4823
+ assertsError(error);
4728
4824
  if (error instanceof UnexpectedError) {
4729
4825
  throw error;
4730
4826
  }
@@ -4794,9 +4890,7 @@ async function executeAttempts(options) {
4794
4890
  break scripts;
4795
4891
  }
4796
4892
  catch (error) {
4797
- if (!(error instanceof Error)) {
4798
- throw error;
4799
- }
4893
+ assertsError(error);
4800
4894
  if (error instanceof UnexpectedError) {
4801
4895
  throw error;
4802
4896
  }
@@ -5417,9 +5511,7 @@ async function executePipeline(options) {
5417
5511
  await Promise.all(resolving);
5418
5512
  }
5419
5513
  catch (error /* <- Note: [3] */) {
5420
- if (!(error instanceof Error)) {
5421
- throw error;
5422
- }
5514
+ assertsError(error);
5423
5515
  // Note: No need to rethrow UnexpectedError
5424
5516
  // if (error instanceof UnexpectedError) {
5425
5517
  // Note: Count usage, [๐Ÿง ] Maybe put to separate function executionReportJsonToUsage + DRY [๐Ÿคนโ€โ™‚๏ธ]