@promptbook/core 0.81.0-7 → 0.81.0-9

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.
@@ -9,6 +9,7 @@ import { $provideScrapersForNode } from '../scrapers/_common/register/$provideSc
9
9
  import { FileCacheStorage } from '../storage/file-cache-storage/FileCacheStorage';
10
10
  import { $execCommand } from '../utils/execCommand/$execCommand';
11
11
  import { $execCommands } from '../utils/execCommand/$execCommands';
12
+ import { wizzard } from '../wizzard/wizzard';
12
13
  export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
13
14
  export { createCollectionFromDirectory };
14
15
  export { $provideExecutablesForNode };
@@ -20,3 +21,4 @@ export { $provideScrapersForNode };
20
21
  export { FileCacheStorage };
21
22
  export { $execCommand };
22
23
  export { $execCommands };
24
+ export { wizzard };
@@ -143,6 +143,7 @@ import type { string_name } from '../types/typeAliases';
143
143
  import type { string_parameter_name } from '../types/typeAliases';
144
144
  import type { string_parameter_value } from '../types/typeAliases';
145
145
  import type { Parameters } from '../types/typeAliases';
146
+ import type { InputParameters } from '../types/typeAliases';
146
147
  import type { string_reserved_parameter_name } from '../types/typeAliases';
147
148
  import type { ReservedParameters } from '../types/typeAliases';
148
149
  import type { string_title } from '../types/typeAliases';
@@ -407,6 +408,7 @@ export type { string_name };
407
408
  export type { string_parameter_name };
408
409
  export type { string_parameter_value };
409
410
  export type { Parameters };
411
+ export type { InputParameters };
410
412
  export type { string_reserved_parameter_name };
411
413
  export type { ReservedParameters };
412
414
  export type { string_title };
@@ -1,6 +1,6 @@
1
1
  import type { Promisable } from 'type-fest';
2
2
  import type { TaskProgress } from '../types/TaskProgress';
3
- import type { Parameters } from '../types/typeAliases';
3
+ import type { InputParameters } from '../types/typeAliases';
4
4
  import type { PipelineExecutorResult } from './PipelineExecutorResult';
5
5
  /**
6
6
  * Executor is a simple async function that takes INPUT PARAMETERs and returns result parameters _(along with all intermediate parameters and INPUT PARAMETERs = it extends input object)_.
@@ -11,7 +11,7 @@ import type { PipelineExecutorResult } from './PipelineExecutorResult';
11
11
  * @see https://github.com/webgptorg/promptbook#executor
12
12
  */
13
13
  export type PipelineExecutor = {
14
- (inputParameters: Parameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<PipelineExecutorResult>;
14
+ (inputParameters: InputParameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<PipelineExecutorResult>;
15
15
  };
16
16
  /**
17
17
  * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
@@ -1,7 +1,7 @@
1
1
  import type { Promisable, ReadonlyDeep } from 'type-fest';
2
2
  import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
3
3
  import type { TaskProgress } from '../../types/TaskProgress';
4
- import type { Parameters } from '../../types/typeAliases';
4
+ import type { InputParameters } from '../../types/typeAliases';
5
5
  import type { PipelineExecutorResult } from '../PipelineExecutorResult';
6
6
  import type { CreatePipelineExecutorOptions } from './00-CreatePipelineExecutorOptions';
7
7
  /**
@@ -13,7 +13,7 @@ type ExecutePipelineOptions = Required<CreatePipelineExecutorOptions> & {
13
13
  /**
14
14
  * @@@
15
15
  */
16
- readonly inputParameters: Readonly<Parameters>;
16
+ readonly inputParameters: Readonly<InputParameters>;
17
17
  /**
18
18
  * @@@
19
19
  */
@@ -1,12 +1,21 @@
1
+ import type { PipelineCollection } from '../../collection/PipelineCollection';
1
2
  import type { string_formfactor_name } from '../../formfactors/_common/string_formfactor_name';
2
3
  import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
4
+ /**
5
+ * @@@
6
+ *
7
+ * @singleton
8
+ * @private internal cache of `getBookTemplate`
9
+ */
10
+ export declare let templatesPipelineCollection: PipelineCollection | null;
3
11
  /**
4
12
  * Get template for new book
5
13
  *
6
14
  * @public exported from `@promptbook/templates`
7
15
  */
8
- export declare function getBookTemplate(formfactorName: string_formfactor_name): Promise<PipelineJson | null>;
16
+ export declare function getBookTemplate(formfactorName: string_formfactor_name): PipelineJson;
9
17
  /**
18
+ * TODO: !!!!!! Test
10
19
  * TODO: [🧠] Which is the best place for this function
11
20
  * TODO: !!!!!! `book string template notation
12
21
  */
@@ -1,5 +1,6 @@
1
1
  import type { TupleToUnion } from 'type-fest';
2
2
  import { RESERVED_PARAMETER_NAMES } from '../constants';
3
+ import type { really_unknown } from '../utils/organization/really_unknown';
3
4
  /**
4
5
  * Semantic helper
5
6
  */
@@ -107,6 +108,13 @@ export type string_parameter_value = string;
107
108
  * @see https://ptbk.io/parameters
108
109
  */
109
110
  export type Parameters = Exclude<Record<string_parameter_name, string_parameter_value>, ReservedParameters>;
111
+ /**
112
+ * Parameters to pass to execution of the pipeline
113
+ *
114
+ * Note: [🚉] This should be fully serializable as JSON
115
+ * @see https://ptbk.io/parameters
116
+ */
117
+ export type InputParameters = Exclude<Record<string_parameter_name, really_unknown>, ReservedParameters>;
110
118
  /**
111
119
  * Semantic helper
112
120
  * Unique identifier of reserved parameter
@@ -0,0 +1,19 @@
1
+ import { Promisable } from 'type-fest';
2
+ import type { PipelineExecutorResult } from '../execution/PipelineExecutorResult';
3
+ import type { TaskProgress } from '../types/TaskProgress';
4
+ import type { InputParameters } from '../types/typeAliases';
5
+ import type { string_pipeline_url } from '../types/typeAliases';
6
+ /**
7
+ * @@@
8
+ *
9
+ * @public exported from `@promptbook/node`
10
+ */
11
+ export declare const wizzard: {
12
+ /**
13
+ * @@@!!!!!!
14
+ */
15
+ execute(book: string_pipeline_url, inputParameters: InputParameters, onProgress?: ((taskProgress: TaskProgress) => Promisable<void>) | undefined): Promise<PipelineExecutorResult>;
16
+ };
17
+ /**
18
+ * TODO: !!!!!! Add to readmes - one markdown here imported in all packages
19
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/core",
3
- "version": "0.81.0-7",
3
+ "version": "0.81.0-9",
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
@@ -27,7 +27,7 @@
27
27
  * @generated
28
28
  * @see https://github.com/webgptorg/promptbook
29
29
  */
30
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-6';
30
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-8';
31
31
  /**
32
32
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
33
33
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2766,6 +2766,81 @@
2766
2766
  * - [♨] Are tasks prepared
2767
2767
  */
2768
2768
 
2769
+ /**
2770
+ * Format either small or big number
2771
+ *
2772
+ * @public exported from `@promptbook/utils`
2773
+ */
2774
+ function numberToString(value) {
2775
+ if (value === 0) {
2776
+ return '0';
2777
+ }
2778
+ else if (Number.isNaN(value)) {
2779
+ return VALUE_STRINGS.nan;
2780
+ }
2781
+ else if (value === Infinity) {
2782
+ return VALUE_STRINGS.infinity;
2783
+ }
2784
+ else if (value === -Infinity) {
2785
+ return VALUE_STRINGS.negativeInfinity;
2786
+ }
2787
+ for (var exponent = 0; exponent < 15; exponent++) {
2788
+ var factor = Math.pow(10, exponent);
2789
+ var valueRounded = Math.round(value * factor) / factor;
2790
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2791
+ return valueRounded.toFixed(exponent);
2792
+ }
2793
+ }
2794
+ return value.toString();
2795
+ }
2796
+
2797
+ /**
2798
+ * Function `valueToString` will convert the given value to string
2799
+ * This is useful and used in the `templateParameters` function
2800
+ *
2801
+ * Note: This function is not just calling `toString` method
2802
+ * It's more complex and can handle this conversion specifically for LLM models
2803
+ * See `VALUE_STRINGS`
2804
+ *
2805
+ * Note: There are 2 similar functions
2806
+ * - `valueToString` converts value to string for LLM models as human-readable string
2807
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2808
+ *
2809
+ * @public exported from `@promptbook/utils`
2810
+ */
2811
+ function valueToString(value) {
2812
+ try {
2813
+ if (value === '') {
2814
+ return VALUE_STRINGS.empty;
2815
+ }
2816
+ else if (value === null) {
2817
+ return VALUE_STRINGS.null;
2818
+ }
2819
+ else if (value === undefined) {
2820
+ return VALUE_STRINGS.undefined;
2821
+ }
2822
+ else if (typeof value === 'string') {
2823
+ return value;
2824
+ }
2825
+ else if (typeof value === 'number') {
2826
+ return numberToString(value);
2827
+ }
2828
+ else if (value instanceof Date) {
2829
+ return value.toISOString();
2830
+ }
2831
+ else {
2832
+ return JSON.stringify(value);
2833
+ }
2834
+ }
2835
+ catch (error) {
2836
+ if (!(error instanceof Error)) {
2837
+ throw error;
2838
+ }
2839
+ console.error(error);
2840
+ return VALUE_STRINGS.unserializable;
2841
+ }
2842
+ }
2843
+
2769
2844
  /**
2770
2845
  * Serializes an error into a [🚉] JSON-serializable object
2771
2846
  *
@@ -3475,81 +3550,6 @@
3475
3550
  return [input];
3476
3551
  }
3477
3552
 
3478
- /**
3479
- * Format either small or big number
3480
- *
3481
- * @public exported from `@promptbook/utils`
3482
- */
3483
- function numberToString(value) {
3484
- if (value === 0) {
3485
- return '0';
3486
- }
3487
- else if (Number.isNaN(value)) {
3488
- return VALUE_STRINGS.nan;
3489
- }
3490
- else if (value === Infinity) {
3491
- return VALUE_STRINGS.infinity;
3492
- }
3493
- else if (value === -Infinity) {
3494
- return VALUE_STRINGS.negativeInfinity;
3495
- }
3496
- for (var exponent = 0; exponent < 15; exponent++) {
3497
- var factor = Math.pow(10, exponent);
3498
- var valueRounded = Math.round(value * factor) / factor;
3499
- if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
3500
- return valueRounded.toFixed(exponent);
3501
- }
3502
- }
3503
- return value.toString();
3504
- }
3505
-
3506
- /**
3507
- * Function `valueToString` will convert the given value to string
3508
- * This is useful and used in the `templateParameters` function
3509
- *
3510
- * Note: This function is not just calling `toString` method
3511
- * It's more complex and can handle this conversion specifically for LLM models
3512
- * See `VALUE_STRINGS`
3513
- *
3514
- * Note: There are 2 similar functions
3515
- * - `valueToString` converts value to string for LLM models as human-readable string
3516
- * - `asSerializable` converts value to string to preserve full information to be able to convert it back
3517
- *
3518
- * @public exported from `@promptbook/utils`
3519
- */
3520
- function valueToString(value) {
3521
- try {
3522
- if (value === '') {
3523
- return VALUE_STRINGS.empty;
3524
- }
3525
- else if (value === null) {
3526
- return VALUE_STRINGS.null;
3527
- }
3528
- else if (value === undefined) {
3529
- return VALUE_STRINGS.undefined;
3530
- }
3531
- else if (typeof value === 'string') {
3532
- return value;
3533
- }
3534
- else if (typeof value === 'number') {
3535
- return numberToString(value);
3536
- }
3537
- else if (value instanceof Date) {
3538
- return value.toISOString();
3539
- }
3540
- else {
3541
- return JSON.stringify(value);
3542
- }
3543
- }
3544
- catch (error) {
3545
- if (!(error instanceof Error)) {
3546
- throw error;
3547
- }
3548
- console.error(error);
3549
- return VALUE_STRINGS.unserializable;
3550
- }
3551
- }
3552
-
3553
3553
  /**
3554
3554
  * Replaces parameters in template with values from parameters object
3555
3555
  *
@@ -4948,7 +4948,10 @@
4948
4948
  finally { if (e_2) throw e_2.error; }
4949
4949
  return [7 /*endfinally*/];
4950
4950
  case 19:
4951
- parametersToPass = inputParameters;
4951
+ parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
4952
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
4953
+ return [key, valueToString(value)];
4954
+ }));
4952
4955
  _g.label = 20;
4953
4956
  case 20:
4954
4957
  _g.trys.push([20, 25, , 28]);
@@ -9133,6 +9136,8 @@
9133
9136
  }
9134
9137
  // =============================================================
9135
9138
  // Note: 1️⃣ Parsing of the markdown into object
9139
+ // ==============
9140
+ // Note: 1️⃣◽1️⃣ Remove #!shebang and comments
9136
9141
  if (pipelineString.startsWith('#!')) {
9137
9142
  var _g = __read(pipelineString.split('\n')), shebangLine_1 = _g[0], restLines = _g.slice(1);
9138
9143
  if (!(shebangLine_1 || '').includes('ptbk')) {
@@ -9141,10 +9146,21 @@
9141
9146
  pipelineString = restLines.join('\n');
9142
9147
  }
9143
9148
  pipelineString = removeContentComments(pipelineString);
9149
+ // ==============
9150
+ // Note: 1️⃣◽2️⃣ Process flat pipeline
9151
+ // TODO: !!!!!!
9152
+ // const isMarkdownBeginningWithHeadline =
9153
+ // const isMarkdown
9154
+ // const isMarkdown
9155
+ // const isMarkdown
9156
+ // ==============
9157
+ // Note: 1️⃣◽3️⃣ Parse the markdown
9144
9158
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
9145
9159
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
9146
9160
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
9147
9161
  var _h = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _h[0], pipelineSections = _h.slice(1); /* <- Note: [🥞] */
9162
+ // ==============
9163
+ // Note: 1️⃣◽4️⃣ Check markdown structure
9148
9164
  if (pipelineHead === undefined) {
9149
9165
  throw new UnexpectedError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline head is not defined\n\n ".concat(block(getPipelineIdentification()), "\n\n This should never happen, because the pipeline already flattened\n "); }));
9150
9166
  }