@promptbook/cli 0.81.0-8 → 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.
@@ -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,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
@@ -1,7 +1,7 @@
1
1
  import { Promisable } from 'type-fest';
2
2
  import type { PipelineExecutorResult } from '../execution/PipelineExecutorResult';
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 { string_pipeline_url } from '../types/typeAliases';
6
6
  /**
7
7
  * @@@
@@ -12,7 +12,7 @@ export declare const wizzard: {
12
12
  /**
13
13
  * @@@!!!!!!
14
14
  */
15
- run(book: string_pipeline_url, inputParameters: Parameters, onProgress?: ((taskProgress: TaskProgress) => Promisable<void>) | undefined): Promise<PipelineExecutorResult>;
15
+ execute(book: string_pipeline_url, inputParameters: InputParameters, onProgress?: ((taskProgress: TaskProgress) => Promisable<void>) | undefined): Promise<PipelineExecutorResult>;
16
16
  };
17
17
  /**
18
18
  * TODO: !!!!!! Add to readmes - one markdown here imported in all packages
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/cli",
3
- "version": "0.81.0-8",
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
@@ -51,7 +51,7 @@
51
51
  * @generated
52
52
  * @see https://github.com/webgptorg/promptbook
53
53
  */
54
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-7';
54
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-8';
55
55
  /**
56
56
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
57
57
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -3914,6 +3914,81 @@
3914
3914
  * - [♨] Are tasks prepared
3915
3915
  */
3916
3916
 
3917
+ /**
3918
+ * Format either small or big number
3919
+ *
3920
+ * @public exported from `@promptbook/utils`
3921
+ */
3922
+ function numberToString(value) {
3923
+ if (value === 0) {
3924
+ return '0';
3925
+ }
3926
+ else if (Number.isNaN(value)) {
3927
+ return VALUE_STRINGS.nan;
3928
+ }
3929
+ else if (value === Infinity) {
3930
+ return VALUE_STRINGS.infinity;
3931
+ }
3932
+ else if (value === -Infinity) {
3933
+ return VALUE_STRINGS.negativeInfinity;
3934
+ }
3935
+ for (var exponent = 0; exponent < 15; exponent++) {
3936
+ var factor = Math.pow(10, exponent);
3937
+ var valueRounded = Math.round(value * factor) / factor;
3938
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
3939
+ return valueRounded.toFixed(exponent);
3940
+ }
3941
+ }
3942
+ return value.toString();
3943
+ }
3944
+
3945
+ /**
3946
+ * Function `valueToString` will convert the given value to string
3947
+ * This is useful and used in the `templateParameters` function
3948
+ *
3949
+ * Note: This function is not just calling `toString` method
3950
+ * It's more complex and can handle this conversion specifically for LLM models
3951
+ * See `VALUE_STRINGS`
3952
+ *
3953
+ * Note: There are 2 similar functions
3954
+ * - `valueToString` converts value to string for LLM models as human-readable string
3955
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
3956
+ *
3957
+ * @public exported from `@promptbook/utils`
3958
+ */
3959
+ function valueToString(value) {
3960
+ try {
3961
+ if (value === '') {
3962
+ return VALUE_STRINGS.empty;
3963
+ }
3964
+ else if (value === null) {
3965
+ return VALUE_STRINGS.null;
3966
+ }
3967
+ else if (value === undefined) {
3968
+ return VALUE_STRINGS.undefined;
3969
+ }
3970
+ else if (typeof value === 'string') {
3971
+ return value;
3972
+ }
3973
+ else if (typeof value === 'number') {
3974
+ return numberToString(value);
3975
+ }
3976
+ else if (value instanceof Date) {
3977
+ return value.toISOString();
3978
+ }
3979
+ else {
3980
+ return JSON.stringify(value);
3981
+ }
3982
+ }
3983
+ catch (error) {
3984
+ if (!(error instanceof Error)) {
3985
+ throw error;
3986
+ }
3987
+ console.error(error);
3988
+ return VALUE_STRINGS.unserializable;
3989
+ }
3990
+ }
3991
+
3917
3992
  /**
3918
3993
  * Serializes an error into a [🚉] JSON-serializable object
3919
3994
  *
@@ -4623,81 +4698,6 @@
4623
4698
  return [input];
4624
4699
  }
4625
4700
 
4626
- /**
4627
- * Format either small or big number
4628
- *
4629
- * @public exported from `@promptbook/utils`
4630
- */
4631
- function numberToString(value) {
4632
- if (value === 0) {
4633
- return '0';
4634
- }
4635
- else if (Number.isNaN(value)) {
4636
- return VALUE_STRINGS.nan;
4637
- }
4638
- else if (value === Infinity) {
4639
- return VALUE_STRINGS.infinity;
4640
- }
4641
- else if (value === -Infinity) {
4642
- return VALUE_STRINGS.negativeInfinity;
4643
- }
4644
- for (var exponent = 0; exponent < 15; exponent++) {
4645
- var factor = Math.pow(10, exponent);
4646
- var valueRounded = Math.round(value * factor) / factor;
4647
- if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
4648
- return valueRounded.toFixed(exponent);
4649
- }
4650
- }
4651
- return value.toString();
4652
- }
4653
-
4654
- /**
4655
- * Function `valueToString` will convert the given value to string
4656
- * This is useful and used in the `templateParameters` function
4657
- *
4658
- * Note: This function is not just calling `toString` method
4659
- * It's more complex and can handle this conversion specifically for LLM models
4660
- * See `VALUE_STRINGS`
4661
- *
4662
- * Note: There are 2 similar functions
4663
- * - `valueToString` converts value to string for LLM models as human-readable string
4664
- * - `asSerializable` converts value to string to preserve full information to be able to convert it back
4665
- *
4666
- * @public exported from `@promptbook/utils`
4667
- */
4668
- function valueToString(value) {
4669
- try {
4670
- if (value === '') {
4671
- return VALUE_STRINGS.empty;
4672
- }
4673
- else if (value === null) {
4674
- return VALUE_STRINGS.null;
4675
- }
4676
- else if (value === undefined) {
4677
- return VALUE_STRINGS.undefined;
4678
- }
4679
- else if (typeof value === 'string') {
4680
- return value;
4681
- }
4682
- else if (typeof value === 'number') {
4683
- return numberToString(value);
4684
- }
4685
- else if (value instanceof Date) {
4686
- return value.toISOString();
4687
- }
4688
- else {
4689
- return JSON.stringify(value);
4690
- }
4691
- }
4692
- catch (error) {
4693
- if (!(error instanceof Error)) {
4694
- throw error;
4695
- }
4696
- console.error(error);
4697
- return VALUE_STRINGS.unserializable;
4698
- }
4699
- }
4700
-
4701
4701
  /**
4702
4702
  * Replaces parameters in template with values from parameters object
4703
4703
  *
@@ -5813,7 +5813,10 @@
5813
5813
  finally { if (e_2) throw e_2.error; }
5814
5814
  return [7 /*endfinally*/];
5815
5815
  case 19:
5816
- parametersToPass = inputParameters;
5816
+ parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
5817
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
5818
+ return [key, valueToString(value)];
5819
+ }));
5817
5820
  _g.label = 20;
5818
5821
  case 20:
5819
5822
  _g.trys.push([20, 25, , 28]);
@@ -9689,6 +9692,8 @@
9689
9692
  }
9690
9693
  // =============================================================
9691
9694
  // Note: 1️⃣ Parsing of the markdown into object
9695
+ // ==============
9696
+ // Note: 1️⃣◽1️⃣ Remove #!shebang and comments
9692
9697
  if (pipelineString.startsWith('#!')) {
9693
9698
  var _g = __read(pipelineString.split('\n')), shebangLine_1 = _g[0], restLines = _g.slice(1);
9694
9699
  if (!(shebangLine_1 || '').includes('ptbk')) {
@@ -9697,10 +9702,21 @@
9697
9702
  pipelineString = restLines.join('\n');
9698
9703
  }
9699
9704
  pipelineString = removeContentComments(pipelineString);
9705
+ // ==============
9706
+ // Note: 1️⃣◽2️⃣ Process flat pipeline
9707
+ // TODO: !!!!!!
9708
+ // const isMarkdownBeginningWithHeadline =
9709
+ // const isMarkdown
9710
+ // const isMarkdown
9711
+ // const isMarkdown
9712
+ // ==============
9713
+ // Note: 1️⃣◽3️⃣ Parse the markdown
9700
9714
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
9701
9715
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
9702
9716
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
9703
9717
  var _h = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _h[0], pipelineSections = _h.slice(1); /* <- Note: [🥞] */
9718
+ // ==============
9719
+ // Note: 1️⃣◽4️⃣ Check markdown structure
9704
9720
  if (pipelineHead === undefined) {
9705
9721
  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 "); }));
9706
9722
  }