@promptbook/website-crawler 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
@@ -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-3';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-31';
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,6 +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`
195
+ // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
193
196
  /**
194
197
  * Where to store the temporary downloads
195
198
  *
@@ -241,7 +244,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
241
244
  true);
242
245
  /**
243
246
  * Note: [💞] Ignore a discrepancy between file name and entity name
244
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
247
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
245
248
  */
246
249
 
247
250
  /**
@@ -1055,6 +1058,54 @@ class ParseError extends Error {
1055
1058
  * TODO: Maybe split `ParseError` and `ApplyError`
1056
1059
  */
1057
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
+
1058
1109
  /**
1059
1110
  * Function isValidJsonString will tell you if the string is valid JSON or not
1060
1111
  *
@@ -1066,9 +1117,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1066
1117
  return true;
1067
1118
  }
1068
1119
  catch (error) {
1069
- if (!(error instanceof Error)) {
1070
- throw error;
1071
- }
1120
+ assertsError(error);
1072
1121
  if (error.message.includes('Unexpected token')) {
1073
1122
  return false;
1074
1123
  }
@@ -1394,9 +1443,7 @@ function checkSerializableAsJson(options) {
1394
1443
  JSON.stringify(value); // <- TODO: [0]
1395
1444
  }
1396
1445
  catch (error) {
1397
- if (!(error instanceof Error)) {
1398
- throw error;
1399
- }
1446
+ assertsError(error);
1400
1447
  throw new UnexpectedError(spaceTrim$1((block) => `
1401
1448
  \`${name}\` is not serializable
1402
1449
 
@@ -2185,7 +2232,7 @@ class PipelineExecutionError extends Error {
2185
2232
  }
2186
2233
  }
2187
2234
  /**
2188
- * TODO: !!!!!! Add id to all errors
2235
+ * TODO: [🧠][🌂] Add id to all errors
2189
2236
  */
2190
2237
 
2191
2238
  /**
@@ -2285,6 +2332,19 @@ class CsvFormatError extends AbstractFormatError {
2285
2332
  }
2286
2333
  }
2287
2334
 
2335
+ /**
2336
+ * AuthenticationError is thrown from login function which is dependency of remote server
2337
+ *
2338
+ * @public exported from `@promptbook/core`
2339
+ */
2340
+ class AuthenticationError extends Error {
2341
+ constructor(message) {
2342
+ super(message);
2343
+ this.name = 'AuthenticationError';
2344
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
2345
+ }
2346
+ }
2347
+
2288
2348
  /**
2289
2349
  * This error indicates that the pipeline collection cannot be propperly loaded
2290
2350
  *
@@ -2327,6 +2387,19 @@ class LimitReachedError extends Error {
2327
2387
  }
2328
2388
  }
2329
2389
 
2390
+ /**
2391
+ * Error thrown when a fetch request fails
2392
+ *
2393
+ * @public exported from `@promptbook/core`
2394
+ */
2395
+ class PromptbookFetchError extends Error {
2396
+ constructor(message) {
2397
+ super(message);
2398
+ this.name = 'PromptbookFetchError';
2399
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
2400
+ }
2401
+ }
2402
+
2330
2403
  /**
2331
2404
  * Index of all custom errors
2332
2405
  *
@@ -2347,7 +2420,10 @@ const PROMPTBOOK_ERRORS = {
2347
2420
  PipelineExecutionError,
2348
2421
  PipelineLogicError,
2349
2422
  PipelineUrlError,
2423
+ AuthenticationError,
2424
+ PromptbookFetchError,
2350
2425
  UnexpectedError,
2426
+ WrappedError,
2351
2427
  // TODO: [🪑]> VersionMismatchError,
2352
2428
  };
2353
2429
  /**
@@ -2486,8 +2562,8 @@ function createTask(options) {
2486
2562
  updatedAt = new Date();
2487
2563
  errors.push(...executionResult.errors);
2488
2564
  warnings.push(...executionResult.warnings);
2489
- // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2490
- // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2565
+ // <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
2566
+ // TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2491
2567
  // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2492
2568
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2493
2569
  assertsTaskSuccessful(executionResult);
@@ -2497,6 +2573,7 @@ function createTask(options) {
2497
2573
  partialResultSubject.next(executionResult);
2498
2574
  }
2499
2575
  catch (error) {
2576
+ assertsError(error);
2500
2577
  status = 'ERROR';
2501
2578
  errors.push(error);
2502
2579
  partialResultSubject.error(error);
@@ -2563,6 +2640,10 @@ function serializeError(error) {
2563
2640
 
2564
2641
  Cannot serialize error with name "${name}"
2565
2642
 
2643
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2644
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2645
+
2646
+
2566
2647
  ${block(stack || message)}
2567
2648
 
2568
2649
  `));
@@ -2884,14 +2965,15 @@ class MultipleLlmExecutionTools {
2884
2965
  }
2885
2966
  }
2886
2967
  catch (error) {
2887
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
2968
+ assertsError(error);
2969
+ if (error instanceof UnexpectedError) {
2888
2970
  throw error;
2889
2971
  }
2890
2972
  errors.push({ llmExecutionTools, error });
2891
2973
  }
2892
2974
  }
2893
2975
  if (errors.length === 1) {
2894
- throw errors[0];
2976
+ throw errors[0].error;
2895
2977
  }
2896
2978
  else if (errors.length > 1) {
2897
2979
  throw new PipelineExecutionError(
@@ -3225,17 +3307,22 @@ function mimeTypeToExtension(value) {
3225
3307
  /**
3226
3308
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3227
3309
  *
3228
- * @private as default `fetch` function used in Promptbook scrapers
3310
+ * @public exported from `@promptbook/core`
3229
3311
  */
3230
- const scraperFetch = async (url, init) => {
3312
+ const promptbookFetch = async (urlOrRequest, init) => {
3231
3313
  try {
3232
- return await fetch(url, init);
3314
+ return await fetch(urlOrRequest, init);
3233
3315
  }
3234
3316
  catch (error) {
3235
- if (!(error instanceof Error)) {
3236
- throw error;
3317
+ assertsError(error);
3318
+ let url;
3319
+ if (typeof urlOrRequest === 'string') {
3320
+ url = urlOrRequest;
3321
+ }
3322
+ else if (urlOrRequest instanceof Request) {
3323
+ url = urlOrRequest.url;
3237
3324
  }
3238
- throw new KnowledgeScrapeError(spaceTrim$1((block) => `
3325
+ throw new PromptbookFetchError(spaceTrim$1((block) => `
3239
3326
  Can not fetch "${url}"
3240
3327
 
3241
3328
  Fetch error:
@@ -3256,7 +3343,7 @@ const scraperFetch = async (url, init) => {
3256
3343
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3257
3344
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
3258
3345
  var _a;
3259
- const { fetch = scraperFetch } = tools;
3346
+ const { fetch = promptbookFetch } = tools;
3260
3347
  const { knowledgeSourceContent } = knowledgeSource;
3261
3348
  let { name } = knowledgeSource;
3262
3349
  const { rootDirname = null,
@@ -3458,9 +3545,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3458
3545
  knowledgePreparedUnflatten[index] = pieces;
3459
3546
  }
3460
3547
  catch (error) {
3461
- if (!(error instanceof Error)) {
3462
- throw error;
3463
- }
3548
+ assertsError(error);
3464
3549
  console.warn(error);
3465
3550
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3466
3551
  }
@@ -3752,13 +3837,19 @@ function valueToString(value) {
3752
3837
  return value.toISOString();
3753
3838
  }
3754
3839
  else {
3755
- return JSON.stringify(value);
3840
+ try {
3841
+ return JSON.stringify(value);
3842
+ }
3843
+ catch (error) {
3844
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
3845
+ return VALUE_STRINGS.circular;
3846
+ }
3847
+ throw error;
3848
+ }
3756
3849
  }
3757
3850
  }
3758
3851
  catch (error) {
3759
- if (!(error instanceof Error)) {
3760
- throw error;
3761
- }
3852
+ assertsError(error);
3762
3853
  console.error(error);
3763
3854
  return VALUE_STRINGS.unserializable;
3764
3855
  }
@@ -3815,9 +3906,7 @@ function extractVariablesFromJavascript(script) {
3815
3906
  }
3816
3907
  }
3817
3908
  catch (error) {
3818
- if (!(error instanceof Error)) {
3819
- throw error;
3820
- }
3909
+ assertsError(error);
3821
3910
  throw new ParseError(spaceTrim((block) => `
3822
3911
  Can not extract variables from the script
3823
3912
  ${block(error.stack || error.message)}
@@ -4682,9 +4771,7 @@ async function executeAttempts(options) {
4682
4771
  break scripts;
4683
4772
  }
4684
4773
  catch (error) {
4685
- if (!(error instanceof Error)) {
4686
- throw error;
4687
- }
4774
+ assertsError(error);
4688
4775
  if (error instanceof UnexpectedError) {
4689
4776
  throw error;
4690
4777
  }
@@ -4754,9 +4841,7 @@ async function executeAttempts(options) {
4754
4841
  break scripts;
4755
4842
  }
4756
4843
  catch (error) {
4757
- if (!(error instanceof Error)) {
4758
- throw error;
4759
- }
4844
+ assertsError(error);
4760
4845
  if (error instanceof UnexpectedError) {
4761
4846
  throw error;
4762
4847
  }
@@ -5377,9 +5462,7 @@ async function executePipeline(options) {
5377
5462
  await Promise.all(resolving);
5378
5463
  }
5379
5464
  catch (error /* <- Note: [3] */) {
5380
- if (!(error instanceof Error)) {
5381
- throw error;
5382
- }
5465
+ assertsError(error);
5383
5466
  // Note: No need to rethrow UnexpectedError
5384
5467
  // if (error instanceof UnexpectedError) {
5385
5468
  // Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹‍♂️]