@promptbook/editable 0.89.0-9 → 0.92.0-10

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 (56) hide show
  1. package/README.md +9 -7
  2. package/esm/index.es.js +126 -16
  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 +14 -4
  6. package/esm/typings/src/_packages/deepseek.index.d.ts +2 -0
  7. package/esm/typings/src/_packages/google.index.d.ts +2 -0
  8. package/esm/typings/src/_packages/types.index.d.ts +18 -0
  9. package/esm/typings/src/_packages/utils.index.d.ts +6 -0
  10. package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
  11. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
  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 +10 -19
  15. package/esm/typings/src/conversion/archive/loadArchive.d.ts +2 -2
  16. package/esm/typings/src/errors/0-index.d.ts +7 -4
  17. package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
  18. package/esm/typings/src/errors/WrappedError.d.ts +10 -0
  19. package/esm/typings/src/errors/assertsError.d.ts +11 -0
  20. package/esm/typings/src/execution/CommonToolsOptions.d.ts +4 -0
  21. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  22. package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -0
  23. package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +5 -0
  24. package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
  25. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
  26. package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
  27. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
  28. package/esm/typings/src/formats/json/utils/jsonParse.d.ts +11 -0
  29. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
  30. package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
  31. package/esm/typings/src/llm-providers/_common/filterModels.d.ts +15 -0
  32. package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts → $provideEnvFilename.d.ts} +2 -2
  33. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  34. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  35. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
  36. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  37. package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +43 -0
  38. package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
  39. package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +23 -0
  40. package/esm/typings/src/llm-providers/google/google-models.d.ts +23 -0
  41. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
  42. package/esm/typings/src/personas/preparePersona.d.ts +1 -1
  43. package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +4 -2
  44. package/esm/typings/src/remote-server/openapi-types.d.ts +626 -0
  45. package/esm/typings/src/remote-server/openapi.d.ts +581 -0
  46. package/esm/typings/src/remote-server/socket-types/_subtypes/Identification.d.ts +7 -1
  47. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  48. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  49. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  50. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
  51. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  52. package/esm/typings/src/types/typeAliases.d.ts +26 -0
  53. package/package.json +6 -2
  54. package/umd/index.umd.js +126 -16
  55. package/umd/index.umd.js.map +1 -1
  56. 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
@@ -17,7 +17,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
17
17
  * @generated
18
18
  * @see https://github.com/webgptorg/promptbook
19
19
  */
20
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
20
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-10';
21
21
  /**
22
22
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
23
23
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -63,6 +63,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
63
63
  * @public exported from `@promptbook/core`
64
64
  */
65
65
  const ADMIN_GITHUB_NAME = 'hejny';
66
+ // <- TODO: [🐊] Pick the best claim
66
67
  /**
67
68
  * When the title is not provided, the default title is used
68
69
  *
@@ -417,6 +418,54 @@ const bookVersionCommandParser = {
417
418
  },
418
419
  };
419
420
 
421
+ /**
422
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
423
+ *
424
+ * @public exported from `@promptbook/core`
425
+ */
426
+ class WrappedError extends Error {
427
+ constructor(whatWasThrown) {
428
+ const tag = `[🤮]`;
429
+ console.error(tag, whatWasThrown);
430
+ super(spaceTrim$1(`
431
+ Non-Error object was thrown
432
+
433
+ Note: Look for ${tag} in the console for more details
434
+ Please report issue on ${ADMIN_EMAIL}
435
+ `));
436
+ this.name = 'WrappedError';
437
+ Object.setPrototypeOf(this, WrappedError.prototype);
438
+ }
439
+ }
440
+
441
+ /**
442
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
443
+ *
444
+ * @param whatWasThrown Any object that was thrown
445
+ * @returns Nothing if the error is an instance of `Error`
446
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
447
+ *
448
+ * @private within the repository
449
+ */
450
+ function assertsError(whatWasThrown) {
451
+ // Case 1: Handle error which was rethrown as `WrappedError`
452
+ if (whatWasThrown instanceof WrappedError) {
453
+ const wrappedError = whatWasThrown;
454
+ throw wrappedError;
455
+ }
456
+ // Case 2: Handle unexpected errors
457
+ if (whatWasThrown instanceof UnexpectedError) {
458
+ const unexpectedError = whatWasThrown;
459
+ throw unexpectedError;
460
+ }
461
+ // Case 3: Handle standard errors - keep them up to consumer
462
+ if (whatWasThrown instanceof Error) {
463
+ return;
464
+ }
465
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
466
+ throw new WrappedError(whatWasThrown);
467
+ }
468
+
420
469
  /**
421
470
  * Units of text measurement
422
471
  *
@@ -497,6 +546,8 @@ function parseNumber(value) {
497
546
  */
498
547
 
499
548
  /**
549
+ import { WrappedError } from '../../errors/WrappedError';
550
+ import { assertsError } from '../../errors/assertsError';
500
551
  * Parses the expect command
501
552
  *
502
553
  * @see `documentationUrl` for more details
@@ -588,9 +639,7 @@ const expectCommandParser = {
588
639
  };
589
640
  }
590
641
  catch (error) {
591
- if (!(error instanceof Error)) {
592
- throw error;
593
- }
642
+ assertsError(error);
594
643
  throw new ParseError(spaceTrim((block) => `
595
644
  Invalid FORMAT command
596
645
  ${block(error.message)}:
@@ -678,6 +727,46 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
678
727
  // encoding: 'utf-8',
679
728
  });
680
729
 
730
+ /**
731
+ * Function to check if a string is valid CSV
732
+ *
733
+ * @param value The string to check
734
+ * @returns True if the string is a valid CSV string, false otherwise
735
+ *
736
+ * @public exported from `@promptbook/utils`
737
+ */
738
+ function isValidCsvString(value) {
739
+ try {
740
+ // A simple check for CSV format: at least one comma and no invalid characters
741
+ if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
742
+ return true;
743
+ }
744
+ return false;
745
+ }
746
+ catch (error) {
747
+ assertsError(error);
748
+ return false;
749
+ }
750
+ }
751
+
752
+ /**
753
+ * Converts a CSV string into an object
754
+ *
755
+ * Note: This is wrapper around `papaparse.parse()` with better autohealing
756
+ *
757
+ * @private - for now until `@promptbook/csv` is released
758
+ */
759
+ function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
760
+ settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
761
+ // Note: Autoheal invalid '\n' characters
762
+ if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
763
+ console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
764
+ value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
765
+ }
766
+ const csv = parse(value, settings);
767
+ return csv;
768
+ }
769
+
681
770
  /**
682
771
  * Definition for CSV spreadsheet
683
772
  *
@@ -688,7 +777,7 @@ const CsvFormatDefinition = {
688
777
  formatName: 'CSV',
689
778
  aliases: ['SPREADSHEET', 'TABLE'],
690
779
  isValid(value, settings, schema) {
691
- return true;
780
+ return isValidCsvString(value);
692
781
  },
693
782
  canBeValid(partialValue, settings, schema) {
694
783
  return true;
@@ -700,8 +789,7 @@ const CsvFormatDefinition = {
700
789
  {
701
790
  subvalueName: 'ROW',
702
791
  async mapValues(value, outputParameterName, settings, mapCallback) {
703
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
704
- const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
792
+ const csv = csvParse(value, settings);
705
793
  if (csv.errors.length !== 0) {
706
794
  throw new CsvFormatError(spaceTrim((block) => `
707
795
  CSV parsing error
@@ -731,8 +819,7 @@ const CsvFormatDefinition = {
731
819
  {
732
820
  subvalueName: 'CELL',
733
821
  async mapValues(value, outputParameterName, settings, mapCallback) {
734
- // TODO: [👨🏾‍🤝‍👨🏼] DRY csv parsing
735
- const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
822
+ const csv = csvParse(value, settings);
736
823
  if (csv.errors.length !== 0) {
737
824
  throw new CsvFormatError(spaceTrim((block) => `
738
825
  CSV parsing error
@@ -769,6 +856,9 @@ const CsvFormatDefinition = {
769
856
  /**
770
857
  * Function isValidJsonString will tell you if the string is valid JSON or not
771
858
  *
859
+ * @param value The string to check
860
+ * @returns True if the string is a valid JSON string, false otherwise
861
+ *
772
862
  * @public exported from `@promptbook/utils`
773
863
  */
774
864
  function isValidJsonString(value /* <- [👨‍⚖️] */) {
@@ -777,9 +867,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
777
867
  return true;
778
868
  }
779
869
  catch (error) {
780
- if (!(error instanceof Error)) {
781
- throw error;
782
- }
870
+ assertsError(error);
783
871
  if (error.message.includes('Unexpected token')) {
784
872
  return false;
785
873
  }
@@ -863,6 +951,30 @@ const TextFormatDefinition = {
863
951
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
864
952
  */
865
953
 
954
+ /**
955
+ * Function to check if a string is valid XML
956
+ *
957
+ * @param value
958
+ * @returns True if the string is a valid XML string, false otherwise
959
+ *
960
+ * @public exported from `@promptbook/utils`
961
+ */
962
+ function isValidXmlString(value) {
963
+ try {
964
+ const parser = new DOMParser();
965
+ const parsedDocument = parser.parseFromString(value, 'application/xml');
966
+ const parserError = parsedDocument.getElementsByTagName('parsererror');
967
+ if (parserError.length > 0) {
968
+ return false;
969
+ }
970
+ return true;
971
+ }
972
+ catch (error) {
973
+ assertsError(error);
974
+ return false;
975
+ }
976
+ }
977
+
866
978
  /**
867
979
  * Definition for XML format
868
980
  *
@@ -872,7 +984,7 @@ const XmlFormatDefinition = {
872
984
  formatName: 'XML',
873
985
  mimeType: 'application/xml',
874
986
  isValid(value, settings, schema) {
875
- return true;
987
+ return isValidXmlString(value);
876
988
  },
877
989
  canBeValid(partialValue, settings, schema) {
878
990
  return true;
@@ -1097,9 +1209,7 @@ function checkSerializableAsJson(options) {
1097
1209
  JSON.stringify(value); // <- TODO: [0]
1098
1210
  }
1099
1211
  catch (error) {
1100
- if (!(error instanceof Error)) {
1101
- throw error;
1102
- }
1212
+ assertsError(error);
1103
1213
  throw new UnexpectedError(spaceTrim((block) => `
1104
1214
  \`${name}\` is not serializable
1105
1215