@promptbook/utils 0.80.0 → 0.81.0-11

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 (64) hide show
  1. package/README.md +12 -5
  2. package/esm/index.es.js +151 -53
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/books/index.d.ts +15 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -6
  6. package/esm/typings/src/_packages/editable.index.d.ts +10 -0
  7. package/esm/typings/src/_packages/templates.index.d.ts +4 -0
  8. package/esm/typings/src/_packages/types.index.d.ts +6 -0
  9. package/esm/typings/src/_packages/utils.index.d.ts +10 -2
  10. package/esm/typings/src/_packages/wizzard.index.d.ts +44 -0
  11. package/esm/typings/src/config.d.ts +26 -0
  12. package/esm/typings/src/execution/ExecutionTools.d.ts +7 -0
  13. package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -2
  14. package/esm/typings/src/execution/PromptbookFetch.d.ts +5 -0
  15. package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
  16. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -2
  17. package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +2 -1
  18. package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +2 -1
  19. package/esm/typings/src/high-level-abstractions/index.d.ts +10 -0
  20. package/esm/typings/src/llm-providers/_common/register/{$provideLlmToolsForCli.d.ts → $provideLlmToolsForWizzardOrCli.d.ts} +2 -2
  21. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -0
  22. package/esm/typings/src/llm-providers/anthropic-claude/register-constructor.d.ts +2 -0
  23. package/esm/typings/src/llm-providers/azure-openai/register-configuration.d.ts +1 -0
  24. package/esm/typings/src/llm-providers/azure-openai/register-constructor.d.ts +1 -0
  25. package/esm/typings/src/llm-providers/google/register-configuration.d.ts +1 -0
  26. package/esm/typings/src/llm-providers/google/register-constructor.d.ts +1 -0
  27. package/esm/typings/src/llm-providers/openai/register-configuration.d.ts +2 -0
  28. package/esm/typings/src/llm-providers/openai/register-constructor.d.ts +2 -0
  29. package/esm/typings/src/other/templates/getBookTemplate.d.ts +21 -0
  30. package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +10 -0
  31. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +10 -0
  32. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
  33. package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +7 -0
  34. package/esm/typings/src/scrapers/document/register-constructor.d.ts +1 -0
  35. package/esm/typings/src/scrapers/document/register-metadata.d.ts +1 -0
  36. package/esm/typings/src/scrapers/document-legacy/register-constructor.d.ts +1 -0
  37. package/esm/typings/src/scrapers/document-legacy/register-metadata.d.ts +1 -0
  38. package/esm/typings/src/scrapers/markdown/register-constructor.d.ts +1 -0
  39. package/esm/typings/src/scrapers/markdown/register-metadata.d.ts +1 -0
  40. package/esm/typings/src/scrapers/pdf/register-constructor.d.ts +1 -0
  41. package/esm/typings/src/scrapers/pdf/register-metadata.d.ts +1 -0
  42. package/esm/typings/src/scrapers/website/register-constructor.d.ts +1 -0
  43. package/esm/typings/src/scrapers/website/register-metadata.d.ts +1 -0
  44. package/esm/typings/src/types/typeAliases.d.ts +8 -0
  45. package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +27 -0
  46. package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.d.ts +3 -3
  47. package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.d.ts +3 -3
  48. package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.d.ts +2 -2
  49. package/esm/typings/src/utils/parameters/numberToString.d.ts +7 -0
  50. package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +6 -2
  51. package/esm/typings/src/utils/parameters/valueToString.d.ts +17 -0
  52. package/esm/typings/src/utils/parameters/valueToString.test.d.ts +1 -0
  53. package/esm/typings/src/utils/serialization/asSerializable.d.ts +4 -0
  54. package/esm/typings/src/version.d.ts +7 -0
  55. package/esm/typings/src/wizzard/wizzard.d.ts +51 -0
  56. package/package.json +1 -1
  57. package/umd/index.umd.js +155 -53
  58. package/umd/index.umd.js.map +1 -1
  59. package/esm/typings/src/utils/formatNumber.d.ts +0 -6
  60. /package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.test.d.ts +0 -0
  61. /package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.test.d.ts +0 -0
  62. /package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.test.d.ts +0 -0
  63. /package/esm/typings/src/utils/{formatNumber.test.d.ts → parameters/numberToString.test.d.ts} +0 -0
  64. /package/esm/typings/src/utils/parameters/{replaceParameters.test.d.ts → templateParameters.test.d.ts} +0 -0
@@ -0,0 +1,51 @@
1
+ import { Promisable } from 'type-fest';
2
+ import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
3
+ import type { ExecutionTools } from '../execution/ExecutionTools';
4
+ import type { PipelineExecutorResult } from '../execution/PipelineExecutorResult';
5
+ import type { PipelineString } from '../pipeline/PipelineString';
6
+ import type { TaskProgress } from '../types/TaskProgress';
7
+ import type { InputParameters } from '../types/typeAliases';
8
+ import type { string_filename } from '../types/typeAliases';
9
+ import type { string_pipeline_url } from '../types/typeAliases';
10
+ /**
11
+ * Look at `wizzard` for more details
12
+ *
13
+ * @private just for single instance
14
+ */
15
+ declare class Wizzard {
16
+ /**
17
+ * @@@!!!!!!
18
+ */
19
+ execute(book: string_pipeline_url, inputParameters: InputParameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<PipelineExecutorResult>;
20
+ private executionTools;
21
+ /**
22
+ * @@@!!!
23
+ *
24
+ * @param pipelineSource
25
+ */
26
+ getExecutionTools(): Promise<ExecutionTools>;
27
+ /**
28
+ * TODO: Make standalone function from this exported from node and used here and in `ptbk run`
29
+ * @@@!!!
30
+ *
31
+ * Strategies:
32
+ * 1) @@@!!!
33
+ * 2) @@@!!!
34
+ *
35
+ * @param pipelineSource
36
+ */
37
+ getPipeline(pipelineSource: string_filename | string_pipeline_url | PipelineString): Promise<PipelineJson>;
38
+ }
39
+ /**
40
+ * 🧙‍♂️ @@@
41
+ *
42
+ * @singleton
43
+ * @public exported from `@promptbook/wizzard`
44
+ */
45
+ export declare const wizzard: Wizzard;
46
+ export {};
47
+ /**
48
+ * TODO: !!!!!! Mark in jsdoc as non-pure
49
+ * TODO: !!!!!! Add to readmes - one markdown here imported in all packages
50
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
51
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/utils",
3
- "version": "0.80.0",
3
+ "version": "0.81.0-11",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "--note-0": " <- [🐊]",
6
6
  "private": false,
package/umd/index.umd.js CHANGED
@@ -12,20 +12,86 @@
12
12
  /**
13
13
  * The version of the Book language
14
14
  *
15
+ * @generated
15
16
  * @see https://github.com/webgptorg/book
16
17
  */
17
18
  var BOOK_LANGUAGE_VERSION = '1.0.0';
18
19
  /**
19
20
  * The version of the Promptbook engine
20
21
  *
22
+ * @generated
21
23
  * @see https://github.com/webgptorg/promptbook
22
24
  */
23
- var PROMPTBOOK_ENGINE_VERSION = '0.80.0-1';
25
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-10';
24
26
  /**
25
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
26
28
  * Note: [💞] Ignore a discrepancy between file name and entity name
27
29
  */
28
30
 
31
+ /**
32
+ * Name for the Promptbook
33
+ *
34
+ * TODO: [🗽] Unite branding and make single place for it
35
+ *
36
+ * @public exported from `@promptbook/core`
37
+ */
38
+ var NAME = "Promptbook";
39
+ /**
40
+ * Email of the responsible person
41
+ *
42
+ * @public exported from `@promptbook/core`
43
+ */
44
+ var ADMIN_EMAIL = 'me@pavolhejny.com';
45
+ /**
46
+ * Name of the responsible person for the Promptbook on GitHub
47
+ *
48
+ * @public exported from `@promptbook/core`
49
+ */
50
+ var ADMIN_GITHUB_NAME = 'hejny';
51
+ // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
52
+ /**
53
+ * The maximum number of iterations for a loops
54
+ *
55
+ * @private within the repository - too low-level in comparison with other `MAX_...`
56
+ */
57
+ var LOOP_LIMIT = 1000;
58
+ /**
59
+ * Strings to represent various values in the context of parameter values
60
+ *
61
+ * @public exported from `@promptbook/utils`
62
+ */
63
+ var VALUE_STRINGS = {
64
+ empty: '(nothing; empty string)',
65
+ null: '(no value; null)',
66
+ undefined: '(unknown value; undefined)',
67
+ nan: '(not a number; NaN)',
68
+ infinity: '(infinity; ∞)',
69
+ negativeInfinity: '(negative infinity; -∞)',
70
+ unserializable: '(unserializable value)',
71
+ };
72
+ /**
73
+ * Small number limit
74
+ *
75
+ * @public exported from `@promptbook/utils`
76
+ */
77
+ var SMALL_NUMBER = 0.001;
78
+ // <- TODO: [🧜‍♂️]
79
+ /**
80
+ * @@@
81
+ *
82
+ * @public exported from `@promptbook/core`
83
+ */
84
+ Object.freeze({
85
+ delimiter: ',',
86
+ quoteChar: '"',
87
+ newline: '\n',
88
+ skipEmptyLines: true,
89
+ });
90
+ /**
91
+ * Note: [💞] Ignore a discrepancy between file name and entity name
92
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
93
+ */
94
+
29
95
  /*! *****************************************************************************
30
96
  Copyright (c) Microsoft Corporation.
31
97
 
@@ -145,50 +211,6 @@
145
211
  return to.concat(ar || Array.prototype.slice.call(from));
146
212
  }
147
213
 
148
- /**
149
- * Name for the Promptbook
150
- *
151
- * TODO: [🗽] Unite branding and make single place for it
152
- *
153
- * @public exported from `@promptbook/core`
154
- */
155
- var NAME = "Promptbook";
156
- /**
157
- * Email of the responsible person
158
- *
159
- * @public exported from `@promptbook/core`
160
- */
161
- var ADMIN_EMAIL = 'me@pavolhejny.com';
162
- /**
163
- * Name of the responsible person for the Promptbook on GitHub
164
- *
165
- * @public exported from `@promptbook/core`
166
- */
167
- var ADMIN_GITHUB_NAME = 'hejny';
168
- // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
169
- /**
170
- * The maximum number of iterations for a loops
171
- *
172
- * @private within the repository - too low-level in comparison with other `MAX_...`
173
- */
174
- var LOOP_LIMIT = 1000;
175
- // <- TODO: [🧜‍♂️]
176
- /**
177
- * @@@
178
- *
179
- * @public exported from `@promptbook/core`
180
- */
181
- Object.freeze({
182
- delimiter: ',',
183
- quoteChar: '"',
184
- newline: '\n',
185
- skipEmptyLines: true,
186
- });
187
- /**
188
- * Note: [💞] Ignore a discrepancy between file name and entity name
189
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
190
- */
191
-
192
214
  /**
193
215
  * Make error report URL for the given error
194
216
  *
@@ -1710,6 +1732,34 @@
1710
1732
  return parameterNames;
1711
1733
  }
1712
1734
 
1735
+ /**
1736
+ * Format either small or big number
1737
+ *
1738
+ * @public exported from `@promptbook/utils`
1739
+ */
1740
+ function numberToString(value) {
1741
+ if (value === 0) {
1742
+ return '0';
1743
+ }
1744
+ else if (Number.isNaN(value)) {
1745
+ return VALUE_STRINGS.nan;
1746
+ }
1747
+ else if (value === Infinity) {
1748
+ return VALUE_STRINGS.infinity;
1749
+ }
1750
+ else if (value === -Infinity) {
1751
+ return VALUE_STRINGS.negativeInfinity;
1752
+ }
1753
+ for (var exponent = 0; exponent < 15; exponent++) {
1754
+ var factor = Math.pow(10, exponent);
1755
+ var valueRounded = Math.round(value * factor) / factor;
1756
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
1757
+ return valueRounded.toFixed(exponent);
1758
+ }
1759
+ }
1760
+ return value.toString();
1761
+ }
1762
+
1713
1763
  /**
1714
1764
  * Freezes the given object and all its nested objects recursively
1715
1765
  *
@@ -1972,16 +2022,66 @@
1972
2022
  * Note: [💞] Ignore a discrepancy between file name and entity name
1973
2023
  */
1974
2024
 
2025
+ /**
2026
+ * Function `valueToString` will convert the given value to string
2027
+ * This is useful and used in the `templateParameters` function
2028
+ *
2029
+ * Note: This function is not just calling `toString` method
2030
+ * It's more complex and can handle this conversion specifically for LLM models
2031
+ * See `VALUE_STRINGS`
2032
+ *
2033
+ * Note: There are 2 similar functions
2034
+ * - `valueToString` converts value to string for LLM models as human-readable string
2035
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2036
+ *
2037
+ * @public exported from `@promptbook/utils`
2038
+ */
2039
+ function valueToString(value) {
2040
+ try {
2041
+ if (value === '') {
2042
+ return VALUE_STRINGS.empty;
2043
+ }
2044
+ else if (value === null) {
2045
+ return VALUE_STRINGS.null;
2046
+ }
2047
+ else if (value === undefined) {
2048
+ return VALUE_STRINGS.undefined;
2049
+ }
2050
+ else if (typeof value === 'string') {
2051
+ return value;
2052
+ }
2053
+ else if (typeof value === 'number') {
2054
+ return numberToString(value);
2055
+ }
2056
+ else if (value instanceof Date) {
2057
+ return value.toISOString();
2058
+ }
2059
+ else {
2060
+ return JSON.stringify(value);
2061
+ }
2062
+ }
2063
+ catch (error) {
2064
+ if (!(error instanceof Error)) {
2065
+ throw error;
2066
+ }
2067
+ console.error(error);
2068
+ return VALUE_STRINGS.unserializable;
2069
+ }
2070
+ }
2071
+
1975
2072
  /**
1976
2073
  * Replaces parameters in template with values from parameters object
1977
2074
  *
2075
+ * Note: This function is not places strings into string,
2076
+ * It's more complex and can handle this operation specifically for LLM models
2077
+ *
1978
2078
  * @param template the template with parameters in {curly} braces
1979
2079
  * @param parameters the object with parameters
1980
2080
  * @returns the template with replaced parameters
1981
2081
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
1982
2082
  * @public exported from `@promptbook/utils`
1983
2083
  */
1984
- function replaceParameters(template, parameters) {
2084
+ function templateParameters(template, parameters) {
1985
2085
  var e_1, _a;
1986
2086
  try {
1987
2087
  for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -2007,7 +2107,7 @@
2007
2107
  var loopLimit = LOOP_LIMIT;
2008
2108
  var _loop_1 = function () {
2009
2109
  if (loopLimit-- < 0) {
2010
- throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
2110
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
2011
2111
  }
2012
2112
  var precol = match.groups.precol;
2013
2113
  var parameterName = match.groups.parameterName;
@@ -2024,7 +2124,7 @@
2024
2124
  if (parameterValue === undefined) {
2025
2125
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
2026
2126
  }
2027
- parameterValue = parameterValue.toString();
2127
+ parameterValue = valueToString(parameterValue);
2028
2128
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
2029
2129
  parameterValue = parameterValue
2030
2130
  .split('\n')
@@ -2163,7 +2263,7 @@
2163
2263
  */
2164
2264
  function clonePipeline(pipeline) {
2165
2265
  // Note: Not using spread operator (...) because @@@
2166
- var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations;
2266
+ var pipelineUrl = pipeline.pipelineUrl, sourceFile = pipeline.sourceFile, title = pipeline.title, bookVersion = pipeline.bookVersion, description = pipeline.description, formfactorName = pipeline.formfactorName, parameters = pipeline.parameters, tasks = pipeline.tasks, knowledgeSources = pipeline.knowledgeSources, knowledgePieces = pipeline.knowledgePieces, personas = pipeline.personas, preparations = pipeline.preparations, sources = pipeline.sources;
2167
2267
  return {
2168
2268
  pipelineUrl: pipelineUrl,
2169
2269
  sourceFile: sourceFile,
@@ -2177,6 +2277,7 @@
2177
2277
  knowledgePieces: knowledgePieces,
2178
2278
  personas: personas,
2179
2279
  preparations: preparations,
2280
+ sources: sources,
2180
2281
  };
2181
2282
  }
2182
2283
  /**
@@ -2573,9 +2674,6 @@
2573
2674
  if (!url.startsWith('https://')) {
2574
2675
  return false;
2575
2676
  }
2576
- if (!(url.endsWith('.book.md') || url.endsWith('.book') || url.endsWith('.book.md') || url.endsWith('.ptbk'))) {
2577
- return false;
2578
- }
2579
2677
  if (url.includes('#')) {
2580
2678
  // TODO: [🐠]
2581
2679
  return false;
@@ -2614,6 +2712,8 @@
2614
2712
  exports.DIACRITIC_VARIANTS_LETTERS = DIACRITIC_VARIANTS_LETTERS;
2615
2713
  exports.LINES_PER_STANDARD_PAGE = LINES_PER_STANDARD_PAGE;
2616
2714
  exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
2715
+ exports.SMALL_NUMBER = SMALL_NUMBER;
2716
+ exports.VALUE_STRINGS = VALUE_STRINGS;
2617
2717
  exports.capitalize = capitalize;
2618
2718
  exports.checkSerializableAsJson = checkSerializableAsJson;
2619
2719
  exports.clonePipeline = clonePipeline;
@@ -2653,6 +2753,7 @@
2653
2753
  exports.normalizeTo_camelCase = normalizeTo_camelCase;
2654
2754
  exports.normalizeTo_snake_case = normalizeTo_snake_case;
2655
2755
  exports.normalizeWhitespaces = normalizeWhitespaces;
2756
+ exports.numberToString = numberToString;
2656
2757
  exports.orderJson = orderJson;
2657
2758
  exports.parseKeywords = parseKeywords;
2658
2759
  exports.parseKeywordsFromString = parseKeywordsFromString;
@@ -2661,16 +2762,17 @@
2661
2762
  exports.removeEmojis = removeEmojis;
2662
2763
  exports.removeQuotes = removeQuotes;
2663
2764
  exports.renderPromptbookMermaid = renderPromptbookMermaid;
2664
- exports.replaceParameters = replaceParameters;
2665
2765
  exports.searchKeywords = searchKeywords;
2666
2766
  exports.serializeError = serializeError;
2667
2767
  exports.spaceTrim = spaceTrim;
2668
2768
  exports.splitIntoSentences = splitIntoSentences;
2769
+ exports.templateParameters = templateParameters;
2669
2770
  exports.titleToName = titleToName;
2670
2771
  exports.trimCodeBlock = trimCodeBlock;
2671
2772
  exports.trimEndOfCodeBlock = trimEndOfCodeBlock;
2672
2773
  exports.union = union;
2673
2774
  exports.unwrapResult = unwrapResult;
2775
+ exports.valueToString = valueToString;
2674
2776
 
2675
2777
  Object.defineProperty(exports, '__esModule', { value: true });
2676
2778