@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.
package/esm/index.es.js CHANGED
@@ -28,7 +28,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
28
28
  * @generated
29
29
  * @see https://github.com/webgptorg/promptbook
30
30
  */
31
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-6';
31
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-8';
32
32
  /**
33
33
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
34
34
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2441,6 +2441,81 @@ function isPipelinePrepared(pipeline) {
2441
2441
  * - [♨] Are tasks prepared
2442
2442
  */
2443
2443
 
2444
+ /**
2445
+ * Format either small or big number
2446
+ *
2447
+ * @public exported from `@promptbook/utils`
2448
+ */
2449
+ function numberToString(value) {
2450
+ if (value === 0) {
2451
+ return '0';
2452
+ }
2453
+ else if (Number.isNaN(value)) {
2454
+ return VALUE_STRINGS.nan;
2455
+ }
2456
+ else if (value === Infinity) {
2457
+ return VALUE_STRINGS.infinity;
2458
+ }
2459
+ else if (value === -Infinity) {
2460
+ return VALUE_STRINGS.negativeInfinity;
2461
+ }
2462
+ for (var exponent = 0; exponent < 15; exponent++) {
2463
+ var factor = Math.pow(10, exponent);
2464
+ var valueRounded = Math.round(value * factor) / factor;
2465
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
2466
+ return valueRounded.toFixed(exponent);
2467
+ }
2468
+ }
2469
+ return value.toString();
2470
+ }
2471
+
2472
+ /**
2473
+ * Function `valueToString` will convert the given value to string
2474
+ * This is useful and used in the `templateParameters` function
2475
+ *
2476
+ * Note: This function is not just calling `toString` method
2477
+ * It's more complex and can handle this conversion specifically for LLM models
2478
+ * See `VALUE_STRINGS`
2479
+ *
2480
+ * Note: There are 2 similar functions
2481
+ * - `valueToString` converts value to string for LLM models as human-readable string
2482
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
2483
+ *
2484
+ * @public exported from `@promptbook/utils`
2485
+ */
2486
+ function valueToString(value) {
2487
+ try {
2488
+ if (value === '') {
2489
+ return VALUE_STRINGS.empty;
2490
+ }
2491
+ else if (value === null) {
2492
+ return VALUE_STRINGS.null;
2493
+ }
2494
+ else if (value === undefined) {
2495
+ return VALUE_STRINGS.undefined;
2496
+ }
2497
+ else if (typeof value === 'string') {
2498
+ return value;
2499
+ }
2500
+ else if (typeof value === 'number') {
2501
+ return numberToString(value);
2502
+ }
2503
+ else if (value instanceof Date) {
2504
+ return value.toISOString();
2505
+ }
2506
+ else {
2507
+ return JSON.stringify(value);
2508
+ }
2509
+ }
2510
+ catch (error) {
2511
+ if (!(error instanceof Error)) {
2512
+ throw error;
2513
+ }
2514
+ console.error(error);
2515
+ return VALUE_STRINGS.unserializable;
2516
+ }
2517
+ }
2518
+
2444
2519
  /**
2445
2520
  * Serializes an error into a [🚉] JSON-serializable object
2446
2521
  *
@@ -3150,81 +3225,6 @@ function arrayableToArray(input) {
3150
3225
  return [input];
3151
3226
  }
3152
3227
 
3153
- /**
3154
- * Format either small or big number
3155
- *
3156
- * @public exported from `@promptbook/utils`
3157
- */
3158
- function numberToString(value) {
3159
- if (value === 0) {
3160
- return '0';
3161
- }
3162
- else if (Number.isNaN(value)) {
3163
- return VALUE_STRINGS.nan;
3164
- }
3165
- else if (value === Infinity) {
3166
- return VALUE_STRINGS.infinity;
3167
- }
3168
- else if (value === -Infinity) {
3169
- return VALUE_STRINGS.negativeInfinity;
3170
- }
3171
- for (var exponent = 0; exponent < 15; exponent++) {
3172
- var factor = Math.pow(10, exponent);
3173
- var valueRounded = Math.round(value * factor) / factor;
3174
- if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
3175
- return valueRounded.toFixed(exponent);
3176
- }
3177
- }
3178
- return value.toString();
3179
- }
3180
-
3181
- /**
3182
- * Function `valueToString` will convert the given value to string
3183
- * This is useful and used in the `templateParameters` function
3184
- *
3185
- * Note: This function is not just calling `toString` method
3186
- * It's more complex and can handle this conversion specifically for LLM models
3187
- * See `VALUE_STRINGS`
3188
- *
3189
- * Note: There are 2 similar functions
3190
- * - `valueToString` converts value to string for LLM models as human-readable string
3191
- * - `asSerializable` converts value to string to preserve full information to be able to convert it back
3192
- *
3193
- * @public exported from `@promptbook/utils`
3194
- */
3195
- function valueToString(value) {
3196
- try {
3197
- if (value === '') {
3198
- return VALUE_STRINGS.empty;
3199
- }
3200
- else if (value === null) {
3201
- return VALUE_STRINGS.null;
3202
- }
3203
- else if (value === undefined) {
3204
- return VALUE_STRINGS.undefined;
3205
- }
3206
- else if (typeof value === 'string') {
3207
- return value;
3208
- }
3209
- else if (typeof value === 'number') {
3210
- return numberToString(value);
3211
- }
3212
- else if (value instanceof Date) {
3213
- return value.toISOString();
3214
- }
3215
- else {
3216
- return JSON.stringify(value);
3217
- }
3218
- }
3219
- catch (error) {
3220
- if (!(error instanceof Error)) {
3221
- throw error;
3222
- }
3223
- console.error(error);
3224
- return VALUE_STRINGS.unserializable;
3225
- }
3226
- }
3227
-
3228
3228
  /**
3229
3229
  * Replaces parameters in template with values from parameters object
3230
3230
  *
@@ -4601,7 +4601,10 @@ function executePipeline(options) {
4601
4601
  finally { if (e_2) throw e_2.error; }
4602
4602
  return [7 /*endfinally*/];
4603
4603
  case 19:
4604
- parametersToPass = inputParameters;
4604
+ parametersToPass = Object.fromEntries(Object.entries(inputParameters).map(function (_a) {
4605
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
4606
+ return [key, valueToString(value)];
4607
+ }));
4605
4608
  _g.label = 20;
4606
4609
  case 20:
4607
4610
  _g.trys.push([20, 25, , 28]);
@@ -8780,6 +8783,8 @@ function precompilePipeline(pipelineString) {
8780
8783
  }
8781
8784
  // =============================================================
8782
8785
  // Note: 1️⃣ Parsing of the markdown into object
8786
+ // ==============
8787
+ // Note: 1️⃣◽1️⃣ Remove #!shebang and comments
8783
8788
  if (pipelineString.startsWith('#!')) {
8784
8789
  var _g = __read(pipelineString.split('\n')), shebangLine_1 = _g[0], restLines = _g.slice(1);
8785
8790
  if (!(shebangLine_1 || '').includes('ptbk')) {
@@ -8788,10 +8793,21 @@ function precompilePipeline(pipelineString) {
8788
8793
  pipelineString = restLines.join('\n');
8789
8794
  }
8790
8795
  pipelineString = removeContentComments(pipelineString);
8796
+ // ==============
8797
+ // Note: 1️⃣◽2️⃣ Process flat pipeline
8798
+ // TODO: !!!!!!
8799
+ // const isMarkdownBeginningWithHeadline =
8800
+ // const isMarkdown
8801
+ // const isMarkdown
8802
+ // const isMarkdown
8803
+ // ==============
8804
+ // Note: 1️⃣◽3️⃣ Parse the markdown
8791
8805
  pipelineString = flattenMarkdown(pipelineString) /* <- Note: [🥞] */;
8792
8806
  pipelineString = pipelineString.replaceAll(/`\{(?<parameterName>[a-z0-9_]+)\}`/gi, '{$<parameterName>}');
8793
8807
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
8794
8808
  var _h = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _h[0], pipelineSections = _h.slice(1); /* <- Note: [🥞] */
8809
+ // ==============
8810
+ // Note: 1️⃣◽4️⃣ Check markdown structure
8795
8811
  if (pipelineHead === undefined) {
8796
8812
  throw new UnexpectedError(spaceTrim$1(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 "); }));
8797
8813
  }
@@ -11166,5 +11182,45 @@ function $execCommands(_a) {
11166
11182
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
11167
11183
  */
11168
11184
 
11169
- export { $execCommand, $execCommands, $provideExecutablesForNode, $provideExecutionToolsForNode, $provideFilesystemForNode, $provideLlmToolsConfigurationFromEnv, $provideLlmToolsFromEnv, $provideScrapersForNode, BOOK_LANGUAGE_VERSION, FileCacheStorage, PROMPTBOOK_ENGINE_VERSION, createCollectionFromDirectory };
11185
+ /**
11186
+ * @@@
11187
+ *
11188
+ * @public exported from `@promptbook/node`
11189
+ */
11190
+ var wizzard = {
11191
+ /**
11192
+ * @@@!!!!!!
11193
+ */
11194
+ execute: function (book, inputParameters, onProgress) {
11195
+ return __awaiter(this, void 0, void 0, function () {
11196
+ var tools, collection, pipeline, pipelineExecutor, result;
11197
+ return __generator(this, function (_a) {
11198
+ switch (_a.label) {
11199
+ case 0: return [4 /*yield*/, $provideExecutionToolsForNode()];
11200
+ case 1:
11201
+ tools = _a.sent();
11202
+ return [4 /*yield*/, createCollectionFromDirectory('./books', tools)];
11203
+ case 2:
11204
+ collection = _a.sent();
11205
+ return [4 /*yield*/, collection.getPipelineByUrl(book)];
11206
+ case 3:
11207
+ pipeline = _a.sent();
11208
+ pipelineExecutor = createPipelineExecutor({ pipeline: pipeline, tools: tools });
11209
+ return [4 /*yield*/, pipelineExecutor(inputParameters, onProgress)];
11210
+ case 4:
11211
+ result = _a.sent();
11212
+ // ▶ Fail if the execution was not successful
11213
+ assertsExecutionSuccessful(result);
11214
+ // ▶ Return the result
11215
+ return [2 /*return*/, result];
11216
+ }
11217
+ });
11218
+ });
11219
+ },
11220
+ };
11221
+ /**
11222
+ * TODO: !!!!!! Add to readmes - one markdown here imported in all packages
11223
+ */
11224
+
11225
+ export { $execCommand, $execCommands, $provideExecutablesForNode, $provideExecutionToolsForNode, $provideFilesystemForNode, $provideLlmToolsConfigurationFromEnv, $provideLlmToolsFromEnv, $provideScrapersForNode, BOOK_LANGUAGE_VERSION, FileCacheStorage, PROMPTBOOK_ENGINE_VERSION, createCollectionFromDirectory, wizzard };
11170
11226
  //# sourceMappingURL=index.es.js.map