@promptbook/utils 0.69.0-7 → 0.69.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 (73) hide show
  1. package/README.md +4 -1
  2. package/esm/index.es.js +151 -124
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/promptbook-collection/index.d.ts +0 -3
  5. package/esm/typings/src/_packages/core.index.d.ts +12 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +6 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +4 -4
  8. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
  9. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
  10. package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +1 -1
  11. package/esm/typings/src/commands/FOREACH/ForeachJson.d.ts +6 -5
  12. package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -2
  13. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +1 -1
  14. package/esm/typings/src/config.d.ts +11 -4
  15. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -1
  16. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
  17. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +6 -5
  18. package/esm/typings/src/errors/AbstractFormatError.d.ts +11 -0
  19. package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -0
  20. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +5 -6
  21. package/esm/typings/src/execution/createPipelineExecutor/$OngoingTemplateResult.d.ts +45 -0
  22. package/esm/typings/src/execution/createPipelineExecutor/00-CreatePipelineExecutorSettings.d.ts +10 -0
  23. package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +3 -0
  24. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +5 -2
  25. package/esm/typings/src/execution/createPipelineExecutor/20-executeTemplate.d.ts +3 -0
  26. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatSubvalues.d.ts +15 -0
  27. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempts.d.ts +74 -0
  28. package/esm/typings/src/execution/embeddingVectorToString.d.ts +1 -1
  29. package/esm/typings/src/execution/utils/checkExpectations.d.ts +2 -0
  30. package/esm/typings/src/execution/utils/usageToHuman.d.ts +3 -4
  31. package/esm/typings/src/formats/_common/FormatDefinition.d.ts +14 -15
  32. package/esm/typings/src/formats/_common/FormatSubvalueDefinition.d.ts +31 -0
  33. package/esm/typings/src/formats/csv/{ListFormatDefinition.d.ts → CsvFormatDefinition.d.ts} +6 -3
  34. package/esm/typings/src/formats/csv/CsvFormatError.d.ts +10 -0
  35. package/esm/typings/src/formats/csv/CsvSettings.d.ts +13 -0
  36. package/esm/typings/src/formats/index.d.ts +1 -1
  37. package/esm/typings/src/formats/json/JsonFormatDefinition.d.ts +4 -3
  38. package/esm/typings/src/formats/text/TextFormatDefinition.d.ts +19 -0
  39. package/esm/typings/src/formats/xml/XmlFormatDefinition.d.ts +4 -3
  40. package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +1 -1
  41. package/esm/typings/src/knowledge/prepare-knowledge/pdf/prepareKnowledgeFromPdf.d.ts +1 -1
  42. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +1 -1
  43. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  44. package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
  45. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
  46. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
  47. package/esm/typings/src/personas/preparePersona.d.ts +1 -1
  48. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +1 -1
  49. package/esm/typings/src/prepare/prepareTemplates.d.ts +1 -1
  50. package/esm/typings/src/types/PipelineJson/ParameterJson.d.ts +1 -1
  51. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +1 -1
  52. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +0 -3
  53. package/esm/typings/src/types/execution-report/executionReportJsonToString.d.ts +2 -1
  54. package/esm/typings/src/types/typeAliases.d.ts +1 -1
  55. package/esm/typings/src/utils/expectation-counters/index.d.ts +3 -0
  56. package/esm/typings/src/utils/organization/{f.d.ts → empty_object.d.ts} +5 -1
  57. package/esm/typings/src/utils/organization/just_empty_object.d.ts +12 -0
  58. package/esm/typings/src/utils/{extractParameterNames.d.ts → parameters/extractParameterNames.d.ts} +2 -2
  59. package/esm/typings/src/utils/parameters/mapAvailableToExpectedParameters.d.ts +27 -0
  60. package/esm/typings/src/utils/{replaceParameters.d.ts → parameters/replaceParameters.d.ts} +2 -2
  61. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
  62. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +1 -1
  63. package/esm/typings/src/utils/validators/parameterName/validateParameterName.d.ts +10 -0
  64. package/package.json +16 -12
  65. package/umd/index.umd.js +151 -124
  66. package/umd/index.umd.js.map +1 -1
  67. package/esm/typings/src/execution/createPipelineExecutor/30-executeFormatCell.d.ts +0 -30
  68. package/esm/typings/src/execution/createPipelineExecutor/40-executeAttempt.d.ts +0 -30
  69. package/esm/typings/src/formats/list/ListFormatDefinition.d.ts +0 -16
  70. /package/esm/typings/src/utils/{extractParameterNames.test.d.ts → parameters/extractParameterNames.test.d.ts} +0 -0
  71. /package/esm/typings/src/{execution/utils/usageToHuman.test.d.ts → utils/parameters/mapAvailableToExpectedParameters.test.d.ts} +0 -0
  72. /package/esm/typings/src/utils/{replaceParameters.test.d.ts → parameters/replaceParameters.test.d.ts} +0 -0
  73. /package/esm/typings/src/{personas/preparePersona.test.d.ts → utils/validators/parameterName/validateParameterName.test.d.ts} +0 -0
@@ -23,7 +23,7 @@ export {};
23
23
  /**
24
24
  * TODO: [🧠] Add context to each template (if missing)
25
25
  * TODO: [🧠] What is better name `prepareTemplate` or `prepareTemplateAndParameters`
26
- * TODO: [♨] !!! Prepare index the samples and maybe templates
26
+ * TODO: [♨][main] !!! Prepare index the samples and maybe templates
27
27
  * TODO: Write tests for `preparePipeline`
28
28
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
29
29
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
@@ -33,7 +33,7 @@ export type ParameterJson = {
33
33
  readonly sampleValues?: Array<string_parameter_value>;
34
34
  };
35
35
  /**
36
- * TODO: [🧠] !!!!!! Should be here registered subparameter from foreach or not?
36
+ * TODO: [🧠] Should be here registered subparameters from foreach or not?
37
37
  * TODO: [♈] Probbably move expectations from templates to parameters
38
38
  * TODO: [🍙] Make some standard order of json properties
39
39
  */
@@ -42,7 +42,7 @@ export type PipelineJson = {
42
42
  /**
43
43
  * Version of the .ptbk.json file
44
44
  */
45
- readonly promptbookVersion: string_semantic_version;
45
+ readonly promptbookVersion?: string_semantic_version;
46
46
  /**
47
47
  * Description of the promptbook
48
48
  * It can use multiple paragraphs of simple markdown formatting like **bold**, *italic*, [link](https://example.com), ... BUT not code blocks and structure
@@ -39,6 +39,3 @@ export type ExecutionReportJson = {
39
39
  */
40
40
  readonly promptExecutions: Array<ExecutionPromptReportJson>;
41
41
  };
42
- /**
43
- * TODO: !!!!!! FOREACH in report
44
- */
@@ -1,3 +1,4 @@
1
+ import type { ReadonlyDeep } from 'type-fest';
1
2
  import type { ExecutionReportJson } from './ExecutionReportJson';
2
3
  import type { ExecutionReportString } from './ExecutionReportString';
3
4
  import type { ExecutionReportStringOptions } from './ExecutionReportStringOptions';
@@ -6,7 +7,7 @@ import type { ExecutionReportStringOptions } from './ExecutionReportStringOption
6
7
  *
7
8
  * @public exported from `@promptbook/core`
8
9
  */
9
- export declare function executionReportJsonToString(executionReportJson: ExecutionReportJson, options?: Partial<ExecutionReportStringOptions>): ExecutionReportString;
10
+ export declare function executionReportJsonToString(executionReportJson: ReadonlyDeep<ExecutionReportJson>, options?: Partial<ExecutionReportStringOptions>): ExecutionReportString;
10
11
  /**
11
12
  * TODO: Add mermaid chart for every report
12
13
  * TODO: [🧠] Allow to filter out some parts of the report by options
@@ -592,7 +592,7 @@ export type number_megabytes = number_positive;
592
592
  export type number_gigabytes = number_positive;
593
593
  export type number_terabytes = number_positive;
594
594
  /**.
595
- * TODO: !!! Change "For example" to @example
595
+ * TODO: [main] !!! Change "For example" to @example
596
596
  * TODO: !! Change to branded types
597
597
  * TODO: Delete type aliases that are not exported or used internally
598
598
  */
@@ -6,3 +6,6 @@ import type { ExpectationUnit } from '../../types/PipelineJson/Expectations';
6
6
  * @public exported from `@promptbook/utils`
7
7
  */
8
8
  export declare const CountUtils: Record<ExpectationUnit, (text: string) => ExpectationAmount>;
9
+ /**
10
+ * TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
11
+ */
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Organizational helper to better mark the place where to really use empty object `{}`
3
3
  *
4
+ * Note: There are 2 similar types>
5
+ * - `empty_object` @@@
6
+ * - `just_empty_object` @@@
7
+ *
4
8
  * @private within the repository
5
9
  */
6
- export type really_empty_object = Record<string, never>;
10
+ export type empty_object = {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Organizational helper to better @@@@
3
+ *
4
+ * Note: There are 2 similar types>
5
+ * - `empty_object` @@@
6
+ * - `just_empty_object` @@@
7
+ *
8
+ * Note: In most cases, you should use `empty_object`
9
+ *
10
+ * @private within the repository
11
+ */
12
+ export type just_empty_object = Record<string, never>;
@@ -1,5 +1,5 @@
1
- import type { string_parameter_name } from '../types/typeAliases';
2
- import type { string_template } from '../types/typeAliases';
1
+ import type { string_parameter_name } from '../../types/typeAliases';
2
+ import type { string_template } from '../../types/typeAliases';
3
3
  /**
4
4
  * Parses the template and returns the list of all parameter names
5
5
  *
@@ -0,0 +1,27 @@
1
+ import type { string_parameter_name } from '../../types/typeAliases';
2
+ import type { string_parameter_value } from '../../types/typeAliases';
3
+ /**
4
+ * @@@
5
+ */
6
+ type MakeapAvailableToExpectedParametersOptions = {
7
+ /**
8
+ * @@@
9
+ */
10
+ readonly expectedParameters: Readonly<Record<string_parameter_name, null>>;
11
+ /**
12
+ * @@@
13
+ */
14
+ readonly availableParameters: Readonly<Record<string_parameter_name, string_parameter_value>>;
15
+ };
16
+ /**
17
+ * Maps available parameters to expected parameters
18
+ *
19
+ * The strategy is:
20
+ * 1) @@@
21
+ * 2) @@@
22
+ *
23
+ * @throws {PipelineExecutionError} @@@
24
+ * @private within the repository used in `createPipelineExecutor`
25
+ */
26
+ export declare function mapAvailableToExpectedParameters(options: MakeapAvailableToExpectedParametersOptions): Readonly<Record<string_parameter_name, string_parameter_value>>;
27
+ export {};
@@ -1,5 +1,5 @@
1
- import type { Parameters } from '../types/typeAliases';
2
- import type { string_template } from '../types/typeAliases';
1
+ import type { Parameters } from '../../types/typeAliases';
2
+ import type { string_template } from '../../types/typeAliases';
3
3
  /**
4
4
  * Replaces parameters in template with values from parameters object
5
5
  *
@@ -22,6 +22,6 @@ import type { string_name } from '../../types/typeAliases';
22
22
  export declare function checkSerializableAsJson(name: string_name, value: unknown): void;
23
23
  /**
24
24
  * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
25
- * TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
25
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
26
26
  * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
27
27
  */
@@ -19,6 +19,6 @@
19
19
  */
20
20
  export declare function isSerializableAsJson(value: unknown): boolean;
21
21
  /**
22
- * TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
22
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
23
23
  * TODO: [🧠][💺] Can be done this on type-level?
24
24
  */
@@ -0,0 +1,10 @@
1
+ import type { string_parameter_name } from '../../../types/typeAliases';
2
+ /**
3
+ * Function `validateParameterName` will @@@
4
+ *
5
+ * @param parameterName @@@
6
+ * @returns @@@
7
+ * @throws {ParseError} @@@
8
+ * @private within the repository
9
+ */
10
+ export declare function validateParameterName(parameterName: string): string_parameter_name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/utils",
3
- "version": "0.69.0-7",
3
+ "version": "0.69.0",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -12,21 +12,25 @@
12
12
  "Pavol Hejný <me@pavolhejny.com> (https://www.pavolhejny.com/)"
13
13
  ],
14
14
  "keywords": [
15
- "autogpt",
16
- "openai",
17
- "gpt-3",
18
- "gpt-4",
19
- "chatgpt",
20
15
  "ai",
16
+ "llm",
17
+ "prompt",
18
+ "template",
19
+ "language-model",
20
+ "chatgpt",
21
+ "autogpt",
21
22
  "machine-learning",
22
23
  "natural-language-processing",
23
24
  "nlp",
24
- "prompt",
25
- "template",
26
- "pipeline",
27
- "automation",
28
- "text-generation",
29
- "language-model"
25
+ "openai",
26
+ "gpt-3",
27
+ "gpt-4",
28
+ "gpt-4o",
29
+ "gpt-4o-mini",
30
+ "o1",
31
+ "o1-mini",
32
+ "o1-preview",
33
+ "anthropic"
30
34
  ],
31
35
  "license": "CC-BY-4.0",
32
36
  "bugs": {
package/umd/index.umd.js CHANGED
@@ -12,8 +12,8 @@
12
12
  /**
13
13
  * The version of the Promptbook library
14
14
  */
15
- var PROMPTBOOK_VERSION = '0.69.0-6';
16
- // TODO: !!!! List here all the versions and annotate + put into script
15
+ var PROMPTBOOK_VERSION = '0.69.0-21';
16
+ // TODO: [main] !!!! List here all the versions and annotate + put into script
17
17
 
18
18
  /*! *****************************************************************************
19
19
  Copyright (c) Microsoft Corporation.
@@ -633,9 +633,9 @@
633
633
  return promptbookMermaid;
634
634
  }
635
635
  /**
636
- * TODO: !!!!!! FOREACH in mermaid graph
637
- * TODO: !!!!!! Knowledge in mermaid graph
638
- * TODO: !!!!!! Personas in mermaid graph
636
+ * TODO: !!!!! FOREACH in mermaid graph
637
+ * TODO: !!!!! Knowledge in mermaid graph
638
+ * TODO: !!!!! Personas in mermaid graph
639
639
  * TODO: Maybe use some Mermaid package instead of string templating
640
640
  * TODO: [🕌] When more than 2 functionalities, split into separate functions
641
641
  */
@@ -745,47 +745,47 @@
745
745
  * @public exported from `@promptbook/utils`
746
746
  */
747
747
  function extractParameterNamesFromTemplate(template) {
748
- var e_1, _a, e_2, _b, e_3, _c;
748
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
749
749
  var title = template.title, description = template.description, templateType = template.templateType, content = template.content, preparedContent = template.preparedContent, jokerParameterNames = template.jokerParameterNames, foreach = template.foreach;
750
750
  var parameterNames = new Set();
751
751
  try {
752
- for (var _d = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _e = _d.next(); !_e.done; _e = _d.next()) {
753
- var parameterName = _e.value;
752
+ for (var _e = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(extractParameterNames(title)), false), __read(extractParameterNames(description || '')), false), __read(extractParameterNames(content)), false), __read(extractParameterNames(preparedContent || '')), false)), _f = _e.next(); !_f.done; _f = _e.next()) {
753
+ var parameterName = _f.value;
754
754
  parameterNames.add(parameterName);
755
755
  }
756
756
  }
757
757
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
758
758
  finally {
759
759
  try {
760
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
760
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
761
761
  }
762
762
  finally { if (e_1) throw e_1.error; }
763
763
  }
764
764
  if (templateType === 'SCRIPT_TEMPLATE') {
765
765
  try {
766
- for (var _f = __values(extractVariables(content)), _g = _f.next(); !_g.done; _g = _f.next()) {
767
- var parameterName = _g.value;
766
+ for (var _g = __values(extractVariables(content)), _h = _g.next(); !_h.done; _h = _g.next()) {
767
+ var parameterName = _h.value;
768
768
  parameterNames.add(parameterName);
769
769
  }
770
770
  }
771
771
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
772
772
  finally {
773
773
  try {
774
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
774
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
775
775
  }
776
776
  finally { if (e_2) throw e_2.error; }
777
777
  }
778
778
  }
779
779
  try {
780
- for (var _h = __values(jokerParameterNames || []), _j = _h.next(); !_j.done; _j = _h.next()) {
781
- var jokerName = _j.value;
780
+ for (var _j = __values(jokerParameterNames || []), _k = _j.next(); !_k.done; _k = _j.next()) {
781
+ var jokerName = _k.value;
782
782
  parameterNames.add(jokerName);
783
783
  }
784
784
  }
785
785
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
786
786
  finally {
787
787
  try {
788
- if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
788
+ if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
789
789
  }
790
790
  finally { if (e_3) throw e_3.error; }
791
791
  }
@@ -793,10 +793,22 @@
793
793
  // <- Note {websiteContent} is used in `preparedContent`
794
794
  // Note: [🍭] Fixing dependent subparameterName from FOREACH command
795
795
  if (foreach !== undefined) {
796
- if (parameterNames.has(foreach.subparameterName)) {
797
- parameterNames.delete(foreach.subparameterName);
798
- parameterNames.add(foreach.parameterName);
799
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
796
+ try {
797
+ for (var _l = __values(foreach.inputSubparameterNames), _m = _l.next(); !_m.done; _m = _l.next()) {
798
+ var subparameterName = _m.value;
799
+ if (parameterNames.has(subparameterName)) {
800
+ parameterNames.delete(subparameterName);
801
+ parameterNames.add(foreach.parameterName);
802
+ // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
803
+ }
804
+ }
805
+ }
806
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
807
+ finally {
808
+ try {
809
+ if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
810
+ }
811
+ finally { if (e_4) throw e_4.error; }
800
812
  }
801
813
  }
802
814
  return parameterNames;
@@ -1283,6 +1295,9 @@
1283
1295
  LINES: countLines,
1284
1296
  PAGES: countPages,
1285
1297
  };
1298
+ /**
1299
+ * TODO: [🧠][🤠] This should be probbably as part of `TextFormatDefinition`
1300
+ */
1286
1301
 
1287
1302
  /**
1288
1303
  * Makes first letter of a string uppercase
@@ -1537,108 +1552,6 @@
1537
1552
  return true;
1538
1553
  }
1539
1554
 
1540
- /**
1541
- * Function parseNumber will parse number from string
1542
- *
1543
- * Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
1544
- * Note: it also works only with decimal numbers
1545
- *
1546
- * @returns parsed number
1547
- * @throws {ParseError} if the value is not a number
1548
- *
1549
- * @public exported from `@promptbook/utils`
1550
- */
1551
- function parseNumber(value) {
1552
- var originalValue = value;
1553
- if (typeof value === 'number') {
1554
- value = value.toString(); // <- TODO: Maybe more efficient way to do this
1555
- }
1556
- if (typeof value !== 'string') {
1557
- return 0;
1558
- }
1559
- value = value.trim();
1560
- if (value.startsWith('+')) {
1561
- return parseNumber(value.substring(1));
1562
- }
1563
- if (value.startsWith('-')) {
1564
- var number = parseNumber(value.substring(1));
1565
- if (number === 0) {
1566
- return 0; // <- Note: To prevent -0
1567
- }
1568
- return -number;
1569
- }
1570
- value = value.replace(/,/g, '.');
1571
- value = value.toUpperCase();
1572
- if (value === '') {
1573
- return 0;
1574
- }
1575
- if (value === '♾' || value.startsWith('INF')) {
1576
- return Infinity;
1577
- }
1578
- if (value.includes('/')) {
1579
- var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
1580
- var numerator = parseNumber(numerator_);
1581
- var denominator = parseNumber(denominator_);
1582
- if (denominator === 0) {
1583
- throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
1584
- }
1585
- return numerator / denominator;
1586
- }
1587
- if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
1588
- return 0;
1589
- }
1590
- if (value.includes('E')) {
1591
- var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
1592
- return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
1593
- }
1594
- if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
1595
- throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
1596
- }
1597
- var num = parseFloat(value);
1598
- if (isNaN(num)) {
1599
- throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
1600
- }
1601
- return num;
1602
- }
1603
- /**
1604
- * TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
1605
- * TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
1606
- */
1607
-
1608
- /**
1609
- * Generates random seed
1610
- *
1611
- * Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
1612
- * Warning: This function is not cryptographically secure (it uses Math.random internally)
1613
- * @public exported from `@promptbook/utils`
1614
- */
1615
- function $randomSeed() {
1616
- return Math.random();
1617
- }
1618
-
1619
- /**
1620
- * Removes quotes from a string
1621
- *
1622
- * Tip: This is very usefull for post-processing of the result of the LLM model
1623
- * Note: This function removes only the same quotes from the beginning and the end of the string
1624
- * Note: There are two simmilar functions:
1625
- * - `removeQuotes` which removes only bounding quotes
1626
- * - `unwrapResult` which removes whole introduce sentence
1627
- *
1628
- * @param text optionally quoted text
1629
- * @returns text without quotes
1630
- * @public exported from `@promptbook/utils`
1631
- */
1632
- function removeQuotes(text) {
1633
- if (text.startsWith('"') && text.endsWith('"')) {
1634
- return text.slice(1, -1);
1635
- }
1636
- if (text.startsWith('\'') && text.endsWith('\'')) {
1637
- return text.slice(1, -1);
1638
- }
1639
- return text;
1640
- }
1641
-
1642
1555
  /**
1643
1556
  * @@@
1644
1557
  *
@@ -1792,7 +1705,7 @@
1792
1705
  }
1793
1706
  /**
1794
1707
  * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
1795
- * TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
1708
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
1796
1709
  * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
1797
1710
  */
1798
1711
 
@@ -1857,6 +1770,18 @@
1857
1770
  * @private within the repository
1858
1771
  */
1859
1772
  var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
1773
+ // <- TODO: [🧜‍♂️]
1774
+ /**
1775
+ * @@@
1776
+ *
1777
+ * @public exported from `@promptbook/core`
1778
+ */
1779
+ Object.freeze({
1780
+ delimiter: ',',
1781
+ quoteChar: '"',
1782
+ newline: '\n',
1783
+ skipEmptyLines: true,
1784
+ });
1860
1785
  /**
1861
1786
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
1862
1787
  */
@@ -1940,6 +1865,108 @@
1940
1865
  return replacedTemplate;
1941
1866
  }
1942
1867
 
1868
+ /**
1869
+ * Function parseNumber will parse number from string
1870
+ *
1871
+ * Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
1872
+ * Note: it also works only with decimal numbers
1873
+ *
1874
+ * @returns parsed number
1875
+ * @throws {ParseError} if the value is not a number
1876
+ *
1877
+ * @public exported from `@promptbook/utils`
1878
+ */
1879
+ function parseNumber(value) {
1880
+ var originalValue = value;
1881
+ if (typeof value === 'number') {
1882
+ value = value.toString(); // <- TODO: Maybe more efficient way to do this
1883
+ }
1884
+ if (typeof value !== 'string') {
1885
+ return 0;
1886
+ }
1887
+ value = value.trim();
1888
+ if (value.startsWith('+')) {
1889
+ return parseNumber(value.substring(1));
1890
+ }
1891
+ if (value.startsWith('-')) {
1892
+ var number = parseNumber(value.substring(1));
1893
+ if (number === 0) {
1894
+ return 0; // <- Note: To prevent -0
1895
+ }
1896
+ return -number;
1897
+ }
1898
+ value = value.replace(/,/g, '.');
1899
+ value = value.toUpperCase();
1900
+ if (value === '') {
1901
+ return 0;
1902
+ }
1903
+ if (value === '♾' || value.startsWith('INF')) {
1904
+ return Infinity;
1905
+ }
1906
+ if (value.includes('/')) {
1907
+ var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
1908
+ var numerator = parseNumber(numerator_);
1909
+ var denominator = parseNumber(denominator_);
1910
+ if (denominator === 0) {
1911
+ throw new ParseError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
1912
+ }
1913
+ return numerator / denominator;
1914
+ }
1915
+ if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
1916
+ return 0;
1917
+ }
1918
+ if (value.includes('E')) {
1919
+ var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
1920
+ return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
1921
+ }
1922
+ if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
1923
+ throw new ParseError("Unable to parse number from \"".concat(originalValue, "\""));
1924
+ }
1925
+ var num = parseFloat(value);
1926
+ if (isNaN(num)) {
1927
+ throw new ParseError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
1928
+ }
1929
+ return num;
1930
+ }
1931
+ /**
1932
+ * TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
1933
+ * TODO: [🧠][🌻] Maybe export through `@promptbook/markdown-utils` not `@promptbook/utils`
1934
+ */
1935
+
1936
+ /**
1937
+ * Generates random seed
1938
+ *
1939
+ * Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
1940
+ * Warning: This function is not cryptographically secure (it uses Math.random internally)
1941
+ * @public exported from `@promptbook/utils`
1942
+ */
1943
+ function $randomSeed() {
1944
+ return Math.random();
1945
+ }
1946
+
1947
+ /**
1948
+ * Removes quotes from a string
1949
+ *
1950
+ * Tip: This is very usefull for post-processing of the result of the LLM model
1951
+ * Note: This function removes only the same quotes from the beginning and the end of the string
1952
+ * Note: There are two simmilar functions:
1953
+ * - `removeQuotes` which removes only bounding quotes
1954
+ * - `unwrapResult` which removes whole introduce sentence
1955
+ *
1956
+ * @param text optionally quoted text
1957
+ * @returns text without quotes
1958
+ * @public exported from `@promptbook/utils`
1959
+ */
1960
+ function removeQuotes(text) {
1961
+ if (text.startsWith('"') && text.endsWith('"')) {
1962
+ return text.slice(1, -1);
1963
+ }
1964
+ if (text.startsWith('\'') && text.endsWith('\'')) {
1965
+ return text.slice(1, -1);
1966
+ }
1967
+ return text;
1968
+ }
1969
+
1943
1970
  /**
1944
1971
  * @@@
1945
1972
  *
@@ -2021,7 +2048,7 @@
2021
2048
  }
2022
2049
  }
2023
2050
  /**
2024
- * TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
2051
+ * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
2025
2052
  * TODO: [🧠][💺] Can be done this on type-level?
2026
2053
  */
2027
2054
 
@@ -2336,7 +2363,7 @@
2336
2363
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
2337
2364
  return false;
2338
2365
  }
2339
- // <- TODO: !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
2366
+ // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
2340
2367
  return true;
2341
2368
  }
2342
2369