@promptbook/legacy-documents 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 +8 -4
  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
@@ -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
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
31
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-3';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -91,6 +91,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
91
91
  * @public exported from `@promptbook/core`
92
92
  */
93
93
  const ADMIN_GITHUB_NAME = 'hejny';
94
+ // <- TODO: [๐ŸŠ] Pick the best claim
94
95
  /**
95
96
  * When the title is not provided, the default title is used
96
97
  *
@@ -123,6 +124,7 @@ const VALUE_STRINGS = {
123
124
  infinity: '(infinity; โˆž)',
124
125
  negativeInfinity: '(negative infinity; -โˆž)',
125
126
  unserializable: '(unserializable value)',
127
+ circular: '(circular JSON)',
126
128
  };
127
129
  /**
128
130
  * Small number limit
@@ -162,7 +164,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
162
164
  */
163
165
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
164
166
  // <- TODO: [๐Ÿ•] Make also `BOOKS_DIRNAME_ALTERNATIVES`
165
- // TODO: !!!!!! Just .promptbook dir, hardocode others
167
+ // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
166
168
  /**
167
169
  * Where to store the temporary downloads
168
170
  *
@@ -1070,9 +1072,60 @@ class ParseError extends Error {
1070
1072
  * TODO: Maybe split `ParseError` and `ApplyError`
1071
1073
  */
1072
1074
 
1075
+ /**
1076
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
1077
+ *
1078
+ * @public exported from `@promptbook/core`
1079
+ */
1080
+ class WrappedError extends Error {
1081
+ constructor(whatWasThrown) {
1082
+ const tag = `[๐Ÿคฎ]`;
1083
+ console.error(tag, whatWasThrown);
1084
+ super(spaceTrim(`
1085
+ Non-Error object was thrown
1086
+
1087
+ Note: Look for ${tag} in the console for more details
1088
+ Please report issue on ${ADMIN_EMAIL}
1089
+ `));
1090
+ this.name = 'WrappedError';
1091
+ Object.setPrototypeOf(this, WrappedError.prototype);
1092
+ }
1093
+ }
1094
+
1095
+ /**
1096
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
1097
+ *
1098
+ * @param whatWasThrown Any object that was thrown
1099
+ * @returns Nothing if the error is an instance of `Error`
1100
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
1101
+ *
1102
+ * @private within the repository
1103
+ */
1104
+ function assertsError(whatWasThrown) {
1105
+ // Case 1: Handle error which was rethrown as `WrappedError`
1106
+ if (whatWasThrown instanceof WrappedError) {
1107
+ const wrappedError = whatWasThrown;
1108
+ throw wrappedError;
1109
+ }
1110
+ // Case 2: Handle unexpected errors
1111
+ if (whatWasThrown instanceof UnexpectedError) {
1112
+ const unexpectedError = whatWasThrown;
1113
+ throw unexpectedError;
1114
+ }
1115
+ // Case 3: Handle standard errors - keep them up to consumer
1116
+ if (whatWasThrown instanceof Error) {
1117
+ return;
1118
+ }
1119
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
1120
+ throw new WrappedError(whatWasThrown);
1121
+ }
1122
+
1073
1123
  /**
1074
1124
  * Function isValidJsonString will tell you if the string is valid JSON or not
1075
1125
  *
1126
+ * @param value The string to check
1127
+ * @returns True if the string is a valid JSON string, false otherwise
1128
+ *
1076
1129
  * @public exported from `@promptbook/utils`
1077
1130
  */
1078
1131
  function isValidJsonString(value /* <- [๐Ÿ‘จโ€โš–๏ธ] */) {
@@ -1081,9 +1134,7 @@ function isValidJsonString(value /* <- [๐Ÿ‘จโ€โš–๏ธ] */) {
1081
1134
  return true;
1082
1135
  }
1083
1136
  catch (error) {
1084
- if (!(error instanceof Error)) {
1085
- throw error;
1086
- }
1137
+ assertsError(error);
1087
1138
  if (error.message.includes('Unexpected token')) {
1088
1139
  return false;
1089
1140
  }
@@ -1436,9 +1487,7 @@ function checkSerializableAsJson(options) {
1436
1487
  JSON.stringify(value); // <- TODO: [0]
1437
1488
  }
1438
1489
  catch (error) {
1439
- if (!(error instanceof Error)) {
1440
- throw error;
1441
- }
1490
+ assertsError(error);
1442
1491
  throw new UnexpectedError(spaceTrim$1((block) => `
1443
1492
  \`${name}\` is not serializable
1444
1493
 
@@ -2209,7 +2258,7 @@ class PipelineExecutionError extends Error {
2209
2258
  }
2210
2259
  }
2211
2260
  /**
2212
- * TODO: !!!!!! Add id to all errors
2261
+ * TODO: [๐Ÿง ][๐ŸŒ‚] Add id to all errors
2213
2262
  */
2214
2263
 
2215
2264
  /**
@@ -2420,7 +2469,10 @@ const PROMPTBOOK_ERRORS = {
2420
2469
  PipelineExecutionError,
2421
2470
  PipelineLogicError,
2422
2471
  PipelineUrlError,
2472
+ AuthenticationError,
2473
+ PromptbookFetchError,
2423
2474
  UnexpectedError,
2475
+ WrappedError,
2424
2476
  // TODO: [๐Ÿช‘]> VersionMismatchError,
2425
2477
  };
2426
2478
  /**
@@ -2437,8 +2489,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
2437
2489
  TypeError,
2438
2490
  URIError,
2439
2491
  AggregateError,
2440
- AuthenticationError,
2441
- PromptbookFetchError,
2442
2492
  /*
2443
2493
  Note: Not widely supported
2444
2494
  > InternalError,
@@ -2561,8 +2611,8 @@ function createTask(options) {
2561
2611
  updatedAt = new Date();
2562
2612
  errors.push(...executionResult.errors);
2563
2613
  warnings.push(...executionResult.warnings);
2564
- // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2565
- // TODO: [๐Ÿง ] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2614
+ // <- TODO: [๐ŸŒ‚] Only unique errors and warnings should be added (or filtered)
2615
+ // TODO: [๐Ÿง ] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2566
2616
  // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2567
2617
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2568
2618
  assertsTaskSuccessful(executionResult);
@@ -2572,6 +2622,7 @@ function createTask(options) {
2572
2622
  partialResultSubject.next(executionResult);
2573
2623
  }
2574
2624
  catch (error) {
2625
+ assertsError(error);
2575
2626
  status = 'ERROR';
2576
2627
  errors.push(error);
2577
2628
  partialResultSubject.error(error);
@@ -2963,14 +3014,15 @@ class MultipleLlmExecutionTools {
2963
3014
  }
2964
3015
  }
2965
3016
  catch (error) {
2966
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
3017
+ assertsError(error);
3018
+ if (error instanceof UnexpectedError) {
2967
3019
  throw error;
2968
3020
  }
2969
3021
  errors.push({ llmExecutionTools, error });
2970
3022
  }
2971
3023
  }
2972
3024
  if (errors.length === 1) {
2973
- throw errors[0];
3025
+ throw errors[0].error;
2974
3026
  }
2975
3027
  else if (errors.length > 1) {
2976
3028
  throw new PipelineExecutionError(
@@ -3415,9 +3467,7 @@ const promptbookFetch = async (urlOrRequest, init) => {
3415
3467
  return await fetch(urlOrRequest, init);
3416
3468
  }
3417
3469
  catch (error) {
3418
- if (!(error instanceof Error)) {
3419
- throw error;
3420
- }
3470
+ assertsError(error);
3421
3471
  let url;
3422
3472
  if (typeof urlOrRequest === 'string') {
3423
3473
  url = urlOrRequest;
@@ -3648,9 +3698,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3648
3698
  knowledgePreparedUnflatten[index] = pieces;
3649
3699
  }
3650
3700
  catch (error) {
3651
- if (!(error instanceof Error)) {
3652
- throw error;
3653
- }
3701
+ assertsError(error);
3654
3702
  console.warn(error);
3655
3703
  // <- TODO: [๐Ÿฎ] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3656
3704
  }
@@ -3942,13 +3990,19 @@ function valueToString(value) {
3942
3990
  return value.toISOString();
3943
3991
  }
3944
3992
  else {
3945
- return JSON.stringify(value);
3993
+ try {
3994
+ return JSON.stringify(value);
3995
+ }
3996
+ catch (error) {
3997
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
3998
+ return VALUE_STRINGS.circular;
3999
+ }
4000
+ throw error;
4001
+ }
3946
4002
  }
3947
4003
  }
3948
4004
  catch (error) {
3949
- if (!(error instanceof Error)) {
3950
- throw error;
3951
- }
4005
+ assertsError(error);
3952
4006
  console.error(error);
3953
4007
  return VALUE_STRINGS.unserializable;
3954
4008
  }
@@ -4005,9 +4059,7 @@ function extractVariablesFromJavascript(script) {
4005
4059
  }
4006
4060
  }
4007
4061
  catch (error) {
4008
- if (!(error instanceof Error)) {
4009
- throw error;
4010
- }
4062
+ assertsError(error);
4011
4063
  throw new ParseError(spaceTrim((block) => `
4012
4064
  Can not extract variables from the script
4013
4065
  ${block(error.stack || error.message)}
@@ -4126,6 +4178,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
4126
4178
  // encoding: 'utf-8',
4127
4179
  });
4128
4180
 
4181
+ /**
4182
+ * Function to check if a string is valid CSV
4183
+ *
4184
+ * @param value The string to check
4185
+ * @returns True if the string is a valid CSV string, false otherwise
4186
+ *
4187
+ * @public exported from `@promptbook/utils`
4188
+ */
4189
+ function isValidCsvString(value) {
4190
+ try {
4191
+ // A simple check for CSV format: at least one comma and no invalid characters
4192
+ if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
4193
+ return true;
4194
+ }
4195
+ return false;
4196
+ }
4197
+ catch (error) {
4198
+ assertsError(error);
4199
+ return false;
4200
+ }
4201
+ }
4202
+
4129
4203
  /**
4130
4204
  * Definition for CSV spreadsheet
4131
4205
  *
@@ -4136,7 +4210,7 @@ const CsvFormatDefinition = {
4136
4210
  formatName: 'CSV',
4137
4211
  aliases: ['SPREADSHEET', 'TABLE'],
4138
4212
  isValid(value, settings, schema) {
4139
- return true;
4213
+ return isValidCsvString(value);
4140
4214
  },
4141
4215
  canBeValid(partialValue, settings, schema) {
4142
4216
  return true;
@@ -4290,6 +4364,30 @@ const TextFormatDefinition = {
4290
4364
  * TODO: [๐Ÿข] Allow to expect something inside each item of list and other formats
4291
4365
  */
4292
4366
 
4367
+ /**
4368
+ * Function to check if a string is valid XML
4369
+ *
4370
+ * @param value
4371
+ * @returns True if the string is a valid XML string, false otherwise
4372
+ *
4373
+ * @public exported from `@promptbook/utils`
4374
+ */
4375
+ function isValidXmlString(value) {
4376
+ try {
4377
+ const parser = new DOMParser();
4378
+ const parsedDocument = parser.parseFromString(value, 'application/xml');
4379
+ const parserError = parsedDocument.getElementsByTagName('parsererror');
4380
+ if (parserError.length > 0) {
4381
+ return false;
4382
+ }
4383
+ return true;
4384
+ }
4385
+ catch (error) {
4386
+ assertsError(error);
4387
+ return false;
4388
+ }
4389
+ }
4390
+
4293
4391
  /**
4294
4392
  * Definition for XML format
4295
4393
  *
@@ -4299,7 +4397,7 @@ const XmlFormatDefinition = {
4299
4397
  formatName: 'XML',
4300
4398
  mimeType: 'application/xml',
4301
4399
  isValid(value, settings, schema) {
4302
- return true;
4400
+ return isValidXmlString(value);
4303
4401
  },
4304
4402
  canBeValid(partialValue, settings, schema) {
4305
4403
  return true;
@@ -4872,9 +4970,7 @@ async function executeAttempts(options) {
4872
4970
  break scripts;
4873
4971
  }
4874
4972
  catch (error) {
4875
- if (!(error instanceof Error)) {
4876
- throw error;
4877
- }
4973
+ assertsError(error);
4878
4974
  if (error instanceof UnexpectedError) {
4879
4975
  throw error;
4880
4976
  }
@@ -4944,9 +5040,7 @@ async function executeAttempts(options) {
4944
5040
  break scripts;
4945
5041
  }
4946
5042
  catch (error) {
4947
- if (!(error instanceof Error)) {
4948
- throw error;
4949
- }
5043
+ assertsError(error);
4950
5044
  if (error instanceof UnexpectedError) {
4951
5045
  throw error;
4952
5046
  }
@@ -5567,9 +5661,7 @@ async function executePipeline(options) {
5567
5661
  await Promise.all(resolving);
5568
5662
  }
5569
5663
  catch (error /* <- Note: [3] */) {
5570
- if (!(error instanceof Error)) {
5571
- throw error;
5572
- }
5664
+ assertsError(error);
5573
5665
  // Note: No need to rethrow UnexpectedError
5574
5666
  // if (error instanceof UnexpectedError) {
5575
5667
  // Note: Count usage, [๐Ÿง ] Maybe put to separate function executionReportJsonToUsage + DRY [๐Ÿคนโ€โ™‚๏ธ]