@promptbook/node 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/node",
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,
@@ -54,7 +54,7 @@
54
54
  "module": "./esm/index.es.js",
55
55
  "typings": "./esm/typings/src/_packages/node.index.d.ts",
56
56
  "peerDependencies": {
57
- "@promptbook/core": "0.81.0-7"
57
+ "@promptbook/core": "0.81.0-9"
58
58
  },
59
59
  "dependencies": {
60
60
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -45,7 +45,7 @@
45
45
  * @generated
46
46
  * @see https://github.com/webgptorg/promptbook
47
47
  */
48
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-6';
48
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-8';
49
49
  /**
50
50
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
51
51
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2458,6 +2458,81 @@
2458
2458
  * - [♨] Are tasks prepared
2459
2459
  */
2460
2460
 
2461
+ /**
2462
+ * Format either small or big number
2463
+ *
2464
+ * @public exported from `@promptbook/utils`
2465
+ */
2466
+ function numberToString(value) {
2467
+ if (value === 0) {
2468
+ return '0';
2469
+ }
2470
+ else if (Number.isNaN(value)) {
2471
+ return VALUE_STRINGS.nan;
2472
+ }
2473
+ else if (value === Infinity) {
2474
+ return VALUE_STRINGS.infinity;
2475
+ }
2476
+ else if (value === -Infinity) {
2477
+ return VALUE_STRINGS.negativeInfinity;
2478
+ }
2479
+ for (var exponent = 0; exponent < 15; exponent++) {
2480
+ var factor = Math.pow(10, exponent);
2481
+ var valueRounded = Math.round(value * factor) / factor;
2482
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2483
+ return valueRounded.toFixed(exponent);
2484
+ }
2485
+ }
2486
+ return value.toString();
2487
+ }
2488
+
2489
+ /**
2490
+ * Function `valueToString` will convert the given value to string
2491
+ * This is useful and used in the `templateParameters` function
2492
+ *
2493
+ * Note: This function is not just calling `toString` method
2494
+ * It's more complex and can handle this conversion specifically for LLM models
2495
+ * See `VALUE_STRINGS`
2496
+ *
2497
+ * Note: There are 2 similar functions
2498
+ * - `valueToString` converts value to string for LLM models as human-readable string
2499
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2500
+ *
2501
+ * @public exported from `@promptbook/utils`
2502
+ */
2503
+ function valueToString(value) {
2504
+ try {
2505
+ if (value === '') {
2506
+ return VALUE_STRINGS.empty;
2507
+ }
2508
+ else if (value === null) {
2509
+ return VALUE_STRINGS.null;
2510
+ }
2511
+ else if (value === undefined) {
2512
+ return VALUE_STRINGS.undefined;
2513
+ }
2514
+ else if (typeof value === 'string') {
2515
+ return value;
2516
+ }
2517
+ else if (typeof value === 'number') {
2518
+ return numberToString(value);
2519
+ }
2520
+ else if (value instanceof Date) {
2521
+ return value.toISOString();
2522
+ }
2523
+ else {
2524
+ return JSON.stringify(value);
2525
+ }
2526
+ }
2527
+ catch (error) {
2528
+ if (!(error instanceof Error)) {
2529
+ throw error;
2530
+ }
2531
+ console.error(error);
2532
+ return VALUE_STRINGS.unserializable;
2533
+ }
2534
+ }
2535
+
2461
2536
  /**
2462
2537
  * Serializes an error into a [🚉] JSON-serializable object
2463
2538
  *
@@ -3167,81 +3242,6 @@
3167
3242
  return [input];
3168
3243
  }
3169
3244
 
3170
- /**
3171
- * Format either small or big number
3172
- *
3173
- * @public exported from `@promptbook/utils`
3174
- */
3175
- function numberToString(value) {
3176
- if (value === 0) {
3177
- return '0';
3178
- }
3179
- else if (Number.isNaN(value)) {
3180
- return VALUE_STRINGS.nan;
3181
- }
3182
- else if (value === Infinity) {
3183
- return VALUE_STRINGS.infinity;
3184
- }
3185
- else if (value === -Infinity) {
3186
- return VALUE_STRINGS.negativeInfinity;
3187
- }
3188
- for (var exponent = 0; exponent < 15; exponent++) {
3189
- var factor = Math.pow(10, exponent);
3190
- var valueRounded = Math.round(value * factor) / factor;
3191
- if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
3192
- return valueRounded.toFixed(exponent);
3193
- }
3194
- }
3195
- return value.toString();
3196
- }
3197
-
3198
- /**
3199
- * Function `valueToString` will convert the given value to string
3200
- * This is useful and used in the `templateParameters` function
3201
- *
3202
- * Note: This function is not just calling `toString` method
3203
- * It's more complex and can handle this conversion specifically for LLM models
3204
- * See `VALUE_STRINGS`
3205
- *
3206
- * Note: There are 2 similar functions
3207
- * - `valueToString` converts value to string for LLM models as human-readable string
3208
- * - `asSerializable` converts value to string to preserve full information to be able to convert it back
3209
- *
3210
- * @public exported from `@promptbook/utils`
3211
- */
3212
- function valueToString(value) {
3213
- try {
3214
- if (value === '') {
3215
- return VALUE_STRINGS.empty;
3216
- }
3217
- else if (value === null) {
3218
- return VALUE_STRINGS.null;
3219
- }
3220
- else if (value === undefined) {
3221
- return VALUE_STRINGS.undefined;
3222
- }
3223
- else if (typeof value === 'string') {
3224
- return value;
3225
- }
3226
- else if (typeof value === 'number') {
3227
- return numberToString(value);
3228
- }
3229
- else if (value instanceof Date) {
3230
- return value.toISOString();
3231
- }
3232
- else {
3233
- return JSON.stringify(value);
3234
- }
3235
- }
3236
- catch (error) {
3237
- if (!(error instanceof Error)) {
3238
- throw error;
3239
- }
3240
- console.error(error);
3241
- return VALUE_STRINGS.unserializable;
3242
- }
3243
- }
3244
-
3245
3245
  /**
3246
3246
  * Replaces parameters in template with values from parameters object
3247
3247
  *
@@ -4618,7 +4618,10 @@
4618
4618
  finally { if (e_2) throw e_2.error; }
4619
4619
  return [7 /*endfinally*/];
4620
4620
  case 19:
4621
- parametersToPass = inputParameters;
4621
+ parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
4622
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
4623
+ return [key, valueToString(value)];
4624
+ }));
4622
4625
  _g.label = 20;
4623
4626
  case 20:
4624
4627
  _g.trys.push([20, 25, , 28]);
@@ -8797,6 +8800,8 @@
8797
8800
  }
8798
8801
  // =============================================================
8799
8802
  // Note: 1️⃣ Parsing of the markdown into object
8803
+ // ==============
8804
+ // Note: 1️⃣◽1️⃣ Remove #!shebang and comments
8800
8805
  if (pipelineString.startsWith('#!')) {
8801
8806
  var _g = __read(pipelineString.split('\n')), shebangLine_1 = _g[0], restLines = _g.slice(1);
8802
8807
  if (!(shebangLine_1 || '').includes('ptbk')) {
@@ -8805,10 +8810,21 @@
8805
8810
  pipelineString = restLines.join('\n');
8806
8811
  }
8807
8812
  pipelineString = removeContentComments(pipelineString);
8813
+ // ==============
8814
+ // Note: 1️⃣◽2️⃣ Process flat pipeline
8815
+ // TODO: !!!!!!
8816
+ // const isMarkdownBeginningWithHeadline =
8817
+ // const isMarkdown
8818
+ // const isMarkdown
8819
+ // const isMarkdown
8820
+ // ==============
8821
+ // Note: 1️⃣◽3️⃣ Parse the markdown
8808
8822
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
8809
8823
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
8810
8824
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
8811
8825
  var _h = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _h[0], pipelineSections = _h.slice(1); /* <- Note: [🥞] */
8826
+ // ==============
8827
+ // Note: 1️⃣◽4️⃣ Check markdown structure
8812
8828
  if (pipelineHead === undefined) {
8813
8829
  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 "); }));
8814
8830
  }
@@ -11183,6 +11199,46 @@
11183
11199
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
11184
11200
  */
11185
11201
 
11202
+ /**
11203
+ * @@@
11204
+ *
11205
+ * @public exported from `@promptbook/node`
11206
+ */
11207
+ var wizzard = {
11208
+ /**
11209
+ * @@@!!!!!!
11210
+ */
11211
+ execute: function (book, inputParameters, onProgress) {
11212
+ return __awaiter(this, void 0, void 0, function () {
11213
+ var tools, collection, pipeline, pipelineExecutor, result;
11214
+ return __generator(this, function (_a) {
11215
+ switch (_a.label) {
11216
+ case 0: return [4 /*yield*/, $provideExecutionToolsForNode()];
11217
+ case 1:
11218
+ tools = _a.sent();
11219
+ return [4 /*yield*/, createCollectionFromDirectory('./books', tools)];
11220
+ case 2:
11221
+ collection = _a.sent();
11222
+ return [4 /*yield*/, collection.getPipelineByUrl(book)];
11223
+ case 3:
11224
+ pipeline = _a.sent();
11225
+ pipelineExecutor = createPipelineExecutor({ pipeline: pipeline, tools: tools });
11226
+ return [4 /*yield*/, pipelineExecutor(inputParameters, onProgress)];
11227
+ case 4:
11228
+ result = _a.sent();
11229
+ // ▶ Fail if the execution was not successful
11230
+ assertsExecutionSuccessful(result);
11231
+ // ▶ Return the result
11232
+ return [2 /*return*/, result];
11233
+ }
11234
+ });
11235
+ });
11236
+ },
11237
+ };
11238
+ /**
11239
+ * TODO: !!!!!! Add to readmes - one markdown here imported in all packages
11240
+ */
11241
+
11186
11242
  exports.$execCommand = $execCommand;
11187
11243
  exports.$execCommands = $execCommands;
11188
11244
  exports.$provideExecutablesForNode = $provideExecutablesForNode;
@@ -11195,6 +11251,7 @@
11195
11251
  exports.FileCacheStorage = FileCacheStorage;
11196
11252
  exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;
11197
11253
  exports.createCollectionFromDirectory = createCollectionFromDirectory;
11254
+ exports.wizzard = wizzard;
11198
11255
 
11199
11256
  Object.defineProperty(exports, '__esModule', { value: true });
11200
11257