@promptbook/node 0.80.0-0 → 0.80.0

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/README.md CHANGED
@@ -23,10 +23,6 @@
23
23
 
24
24
 
25
25
 
26
- <blockquote style="color: #ff8811">
27
- <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
- </blockquote>
29
-
30
26
  ## 📦 Package `@promptbook/node`
31
27
 
32
28
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
package/esm/index.es.js CHANGED
@@ -26,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  *
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- var PROMPTBOOK_ENGINE_VERSION = '0.79.0';
29
+ var PROMPTBOOK_ENGINE_VERSION = '0.80.0-1';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -287,256 +287,6 @@ true);
287
287
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
288
288
  */
289
289
 
290
- /**
291
- * Prettify the html code
292
- *
293
- * @param content raw html code
294
- * @returns formatted html code
295
- * @private withing the package because of HUGE size of prettier dependency
296
- */
297
- function prettifyMarkdown(content) {
298
- try {
299
- return format(content, {
300
- parser: 'markdown',
301
- plugins: [parserHtml],
302
- // TODO: DRY - make some import or auto-copy of .prettierrc
303
- endOfLine: 'lf',
304
- tabWidth: 4,
305
- singleQuote: true,
306
- trailingComma: 'all',
307
- arrowParens: 'always',
308
- printWidth: 120,
309
- htmlWhitespaceSensitivity: 'ignore',
310
- jsxBracketSameLine: false,
311
- bracketSpacing: true,
312
- });
313
- }
314
- catch (error) {
315
- // TODO: [🟥] Detect browser / node and make it colorfull
316
- console.error('There was an error with prettifying the markdown, using the original as the fallback', {
317
- error: error,
318
- html: content,
319
- });
320
- return content;
321
- }
322
- }
323
-
324
- /**
325
- * Makes first letter of a string uppercase
326
- *
327
- * @public exported from `@promptbook/utils`
328
- */
329
- function capitalize(word) {
330
- return word.substring(0, 1).toUpperCase() + word.substring(1);
331
- }
332
-
333
- /**
334
- * Converts promptbook in JSON format to string format
335
- *
336
- * @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
337
- * @param pipelineJson Promptbook in JSON format (.book.json)
338
- * @returns Promptbook in string format (.book.md)
339
- * @public exported from `@promptbook/core`
340
- */
341
- function pipelineJsonToString(pipelineJson) {
342
- var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
343
- var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, tasks = pipelineJson.tasks;
344
- var pipelineString = "# ".concat(title);
345
- if (description) {
346
- pipelineString += '\n\n';
347
- pipelineString += description;
348
- }
349
- var commands = [];
350
- if (pipelineUrl) {
351
- commands.push("PIPELINE URL ".concat(pipelineUrl));
352
- }
353
- if (bookVersion !== "undefined") {
354
- commands.push("BOOK VERSION ".concat(bookVersion));
355
- }
356
- // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
357
- pipelineString = prettifyMarkdown(pipelineString);
358
- try {
359
- for (var _g = __values(parameters.filter(function (_a) {
360
- var isInput = _a.isInput;
361
- return isInput;
362
- })), _h = _g.next(); !_h.done; _h = _g.next()) {
363
- var parameter = _h.value;
364
- commands.push("INPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
365
- }
366
- }
367
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
368
- finally {
369
- try {
370
- if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
371
- }
372
- finally { if (e_1) throw e_1.error; }
373
- }
374
- try {
375
- for (var _j = __values(parameters.filter(function (_a) {
376
- var isOutput = _a.isOutput;
377
- return isOutput;
378
- })), _k = _j.next(); !_k.done; _k = _j.next()) {
379
- var parameter = _k.value;
380
- commands.push("OUTPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
381
- }
382
- }
383
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
384
- finally {
385
- try {
386
- if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
387
- }
388
- finally { if (e_2) throw e_2.error; }
389
- }
390
- pipelineString += '\n\n';
391
- pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
392
- try {
393
- for (var tasks_1 = __values(tasks), tasks_1_1 = tasks_1.next(); !tasks_1_1.done; tasks_1_1 = tasks_1.next()) {
394
- var task = tasks_1_1.value;
395
- var
396
- /* Note: Not using:> name, */
397
- title_1 = task.title, description_1 = task.description,
398
- /* Note: dependentParameterNames, */
399
- jokers = task.jokerParameterNames, taskType = task.taskType, content = task.content, postprocessing = task.postprocessingFunctionNames, expectations = task.expectations, format = task.format, resultingParameterName = task.resultingParameterName;
400
- pipelineString += '\n\n';
401
- pipelineString += "## ".concat(title_1);
402
- if (description_1) {
403
- pipelineString += '\n\n';
404
- pipelineString += description_1;
405
- }
406
- var commands_1 = [];
407
- var contentLanguage = 'text';
408
- if (taskType === 'PROMPT_TASK') {
409
- var modelRequirements = task.modelRequirements;
410
- var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
411
- // Note: Do nothing, it is default
412
- // commands.push(`PROMPT`);
413
- if (modelVariant) {
414
- commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
415
- }
416
- if (modelName) {
417
- commands_1.push("MODEL NAME `".concat(modelName, "`"));
418
- }
419
- }
420
- else if (taskType === 'SIMPLE_TASK') {
421
- commands_1.push("SIMPLE TEMPLATE");
422
- // Note: Nothing special here
423
- }
424
- else if (taskType === 'SCRIPT_TASK') {
425
- commands_1.push("SCRIPT");
426
- if (task.contentLanguage) {
427
- contentLanguage = task.contentLanguage;
428
- }
429
- else {
430
- contentLanguage = '';
431
- }
432
- }
433
- else if (taskType === 'DIALOG_TASK') {
434
- commands_1.push("DIALOG");
435
- // Note: Nothing special here
436
- } // <- }else if([🅱]
437
- if (jokers) {
438
- try {
439
- for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
440
- var joker = jokers_1_1.value;
441
- commands_1.push("JOKER {".concat(joker, "}"));
442
- }
443
- }
444
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
445
- finally {
446
- try {
447
- if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
448
- }
449
- finally { if (e_4) throw e_4.error; }
450
- }
451
- } /* not else */
452
- if (postprocessing) {
453
- try {
454
- for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
455
- var postprocessingFunctionName = postprocessing_1_1.value;
456
- commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
457
- }
458
- }
459
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
460
- finally {
461
- try {
462
- if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
463
- }
464
- finally { if (e_5) throw e_5.error; }
465
- }
466
- } /* not else */
467
- if (expectations) {
468
- try {
469
- for (var _m = (e_6 = void 0, __values(Object.entries(expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
470
- var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
471
- if (min === max) {
472
- commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
473
- }
474
- else {
475
- if (min !== undefined) {
476
- commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
477
- } /* not else */
478
- if (max !== undefined) {
479
- commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
480
- }
481
- }
482
- }
483
- }
484
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
485
- finally {
486
- try {
487
- if (_o && !_o.done && (_f = _m.return)) _f.call(_m);
488
- }
489
- finally { if (e_6) throw e_6.error; }
490
- }
491
- } /* not else */
492
- if (format) {
493
- if (format === 'JSON') {
494
- // TODO: @deprecated remove
495
- commands_1.push("FORMAT JSON");
496
- }
497
- } /* not else */
498
- pipelineString += '\n\n';
499
- pipelineString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
500
- pipelineString += '\n\n';
501
- pipelineString += '```' + contentLanguage;
502
- pipelineString += '\n';
503
- pipelineString += spaceTrim(content);
504
- // <- TODO: [main] !!! Escape
505
- // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
506
- pipelineString += '\n';
507
- pipelineString += '```';
508
- pipelineString += '\n\n';
509
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
510
- }
511
- }
512
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
513
- finally {
514
- try {
515
- if (tasks_1_1 && !tasks_1_1.done && (_c = tasks_1.return)) _c.call(tasks_1);
516
- }
517
- finally { if (e_3) throw e_3.error; }
518
- }
519
- return pipelineString;
520
- }
521
- /**
522
- * @private internal utility of `pipelineJsonToString`
523
- */
524
- function taskParameterJsonToString(taskParameterJson) {
525
- var name = taskParameterJson.name, description = taskParameterJson.description;
526
- var parameterString = "{".concat(name, "}");
527
- if (description) {
528
- parameterString = "".concat(parameterString, " ").concat(description);
529
- }
530
- return parameterString;
531
- }
532
- /**
533
- * TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
534
- * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
535
- * TODO: [🏛] Maybe make some markdown builder
536
- * TODO: [🏛] Escape all
537
- * TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
538
- */
539
-
540
290
  /**
541
291
  * Orders JSON object by keys
542
292
  *
@@ -1480,6 +1230,256 @@ function joinLlmExecutionTools() {
1480
1230
 
1481
1231
  var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-persona.book.md"}];
1482
1232
 
1233
+ /**
1234
+ * Prettify the html code
1235
+ *
1236
+ * @param content raw html code
1237
+ * @returns formatted html code
1238
+ * @private withing the package because of HUGE size of prettier dependency
1239
+ */
1240
+ function prettifyMarkdown(content) {
1241
+ try {
1242
+ return format(content, {
1243
+ parser: 'markdown',
1244
+ plugins: [parserHtml],
1245
+ // TODO: DRY - make some import or auto-copy of .prettierrc
1246
+ endOfLine: 'lf',
1247
+ tabWidth: 4,
1248
+ singleQuote: true,
1249
+ trailingComma: 'all',
1250
+ arrowParens: 'always',
1251
+ printWidth: 120,
1252
+ htmlWhitespaceSensitivity: 'ignore',
1253
+ jsxBracketSameLine: false,
1254
+ bracketSpacing: true,
1255
+ });
1256
+ }
1257
+ catch (error) {
1258
+ // TODO: [🟥] Detect browser / node and make it colorfull
1259
+ console.error('There was an error with prettifying the markdown, using the original as the fallback', {
1260
+ error: error,
1261
+ html: content,
1262
+ });
1263
+ return content;
1264
+ }
1265
+ }
1266
+
1267
+ /**
1268
+ * Makes first letter of a string uppercase
1269
+ *
1270
+ * @public exported from `@promptbook/utils`
1271
+ */
1272
+ function capitalize(word) {
1273
+ return word.substring(0, 1).toUpperCase() + word.substring(1);
1274
+ }
1275
+
1276
+ /**
1277
+ * Converts promptbook in JSON format to string format
1278
+ *
1279
+ * @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
1280
+ * @param pipelineJson Promptbook in JSON format (.book.json)
1281
+ * @returns Promptbook in string format (.book.md)
1282
+ * @public exported from `@promptbook/core`
1283
+ */
1284
+ function pipelineJsonToString(pipelineJson) {
1285
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
1286
+ var title = pipelineJson.title, pipelineUrl = pipelineJson.pipelineUrl, bookVersion = pipelineJson.bookVersion, description = pipelineJson.description, parameters = pipelineJson.parameters, tasks = pipelineJson.tasks;
1287
+ var pipelineString = "# ".concat(title);
1288
+ if (description) {
1289
+ pipelineString += '\n\n';
1290
+ pipelineString += description;
1291
+ }
1292
+ var commands = [];
1293
+ if (pipelineUrl) {
1294
+ commands.push("PIPELINE URL ".concat(pipelineUrl));
1295
+ }
1296
+ if (bookVersion !== "undefined") {
1297
+ commands.push("BOOK VERSION ".concat(bookVersion));
1298
+ }
1299
+ // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
1300
+ pipelineString = prettifyMarkdown(pipelineString);
1301
+ try {
1302
+ for (var _g = __values(parameters.filter(function (_a) {
1303
+ var isInput = _a.isInput;
1304
+ return isInput;
1305
+ })), _h = _g.next(); !_h.done; _h = _g.next()) {
1306
+ var parameter = _h.value;
1307
+ commands.push("INPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
1308
+ }
1309
+ }
1310
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1311
+ finally {
1312
+ try {
1313
+ if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
1314
+ }
1315
+ finally { if (e_1) throw e_1.error; }
1316
+ }
1317
+ try {
1318
+ for (var _j = __values(parameters.filter(function (_a) {
1319
+ var isOutput = _a.isOutput;
1320
+ return isOutput;
1321
+ })), _k = _j.next(); !_k.done; _k = _j.next()) {
1322
+ var parameter = _k.value;
1323
+ commands.push("OUTPUT PARAMETER ".concat(taskParameterJsonToString(parameter)));
1324
+ }
1325
+ }
1326
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1327
+ finally {
1328
+ try {
1329
+ if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
1330
+ }
1331
+ finally { if (e_2) throw e_2.error; }
1332
+ }
1333
+ pipelineString += '\n\n';
1334
+ pipelineString += commands.map(function (command) { return "- ".concat(command); }).join('\n');
1335
+ try {
1336
+ for (var tasks_1 = __values(tasks), tasks_1_1 = tasks_1.next(); !tasks_1_1.done; tasks_1_1 = tasks_1.next()) {
1337
+ var task = tasks_1_1.value;
1338
+ var
1339
+ /* Note: Not using:> name, */
1340
+ title_1 = task.title, description_1 = task.description,
1341
+ /* Note: dependentParameterNames, */
1342
+ jokers = task.jokerParameterNames, taskType = task.taskType, content = task.content, postprocessing = task.postprocessingFunctionNames, expectations = task.expectations, format = task.format, resultingParameterName = task.resultingParameterName;
1343
+ pipelineString += '\n\n';
1344
+ pipelineString += "## ".concat(title_1);
1345
+ if (description_1) {
1346
+ pipelineString += '\n\n';
1347
+ pipelineString += description_1;
1348
+ }
1349
+ var commands_1 = [];
1350
+ var contentLanguage = 'text';
1351
+ if (taskType === 'PROMPT_TASK') {
1352
+ var modelRequirements = task.modelRequirements;
1353
+ var _l = modelRequirements || {}, modelName = _l.modelName, modelVariant = _l.modelVariant;
1354
+ // Note: Do nothing, it is default
1355
+ // commands.push(`PROMPT`);
1356
+ if (modelVariant) {
1357
+ commands_1.push("MODEL VARIANT ".concat(capitalize(modelVariant)));
1358
+ }
1359
+ if (modelName) {
1360
+ commands_1.push("MODEL NAME `".concat(modelName, "`"));
1361
+ }
1362
+ }
1363
+ else if (taskType === 'SIMPLE_TASK') {
1364
+ commands_1.push("SIMPLE TEMPLATE");
1365
+ // Note: Nothing special here
1366
+ }
1367
+ else if (taskType === 'SCRIPT_TASK') {
1368
+ commands_1.push("SCRIPT");
1369
+ if (task.contentLanguage) {
1370
+ contentLanguage = task.contentLanguage;
1371
+ }
1372
+ else {
1373
+ contentLanguage = '';
1374
+ }
1375
+ }
1376
+ else if (taskType === 'DIALOG_TASK') {
1377
+ commands_1.push("DIALOG");
1378
+ // Note: Nothing special here
1379
+ } // <- }else if([🅱]
1380
+ if (jokers) {
1381
+ try {
1382
+ for (var jokers_1 = (e_4 = void 0, __values(jokers)), jokers_1_1 = jokers_1.next(); !jokers_1_1.done; jokers_1_1 = jokers_1.next()) {
1383
+ var joker = jokers_1_1.value;
1384
+ commands_1.push("JOKER {".concat(joker, "}"));
1385
+ }
1386
+ }
1387
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1388
+ finally {
1389
+ try {
1390
+ if (jokers_1_1 && !jokers_1_1.done && (_d = jokers_1.return)) _d.call(jokers_1);
1391
+ }
1392
+ finally { if (e_4) throw e_4.error; }
1393
+ }
1394
+ } /* not else */
1395
+ if (postprocessing) {
1396
+ try {
1397
+ for (var postprocessing_1 = (e_5 = void 0, __values(postprocessing)), postprocessing_1_1 = postprocessing_1.next(); !postprocessing_1_1.done; postprocessing_1_1 = postprocessing_1.next()) {
1398
+ var postprocessingFunctionName = postprocessing_1_1.value;
1399
+ commands_1.push("POSTPROCESSING `".concat(postprocessingFunctionName, "`"));
1400
+ }
1401
+ }
1402
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1403
+ finally {
1404
+ try {
1405
+ if (postprocessing_1_1 && !postprocessing_1_1.done && (_e = postprocessing_1.return)) _e.call(postprocessing_1);
1406
+ }
1407
+ finally { if (e_5) throw e_5.error; }
1408
+ }
1409
+ } /* not else */
1410
+ if (expectations) {
1411
+ try {
1412
+ for (var _m = (e_6 = void 0, __values(Object.entries(expectations))), _o = _m.next(); !_o.done; _o = _m.next()) {
1413
+ var _p = __read(_o.value, 2), unit = _p[0], _q = _p[1], min = _q.min, max = _q.max;
1414
+ if (min === max) {
1415
+ commands_1.push("EXPECT EXACTLY ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
1416
+ }
1417
+ else {
1418
+ if (min !== undefined) {
1419
+ commands_1.push("EXPECT MIN ".concat(min, " ").concat(capitalize(unit + (min > 1 ? 's' : ''))));
1420
+ } /* not else */
1421
+ if (max !== undefined) {
1422
+ commands_1.push("EXPECT MAX ".concat(max, " ").concat(capitalize(unit + (max > 1 ? 's' : ''))));
1423
+ }
1424
+ }
1425
+ }
1426
+ }
1427
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1428
+ finally {
1429
+ try {
1430
+ if (_o && !_o.done && (_f = _m.return)) _f.call(_m);
1431
+ }
1432
+ finally { if (e_6) throw e_6.error; }
1433
+ }
1434
+ } /* not else */
1435
+ if (format) {
1436
+ if (format === 'JSON') {
1437
+ // TODO: @deprecated remove
1438
+ commands_1.push("FORMAT JSON");
1439
+ }
1440
+ } /* not else */
1441
+ pipelineString += '\n\n';
1442
+ pipelineString += commands_1.map(function (command) { return "- ".concat(command); }).join('\n');
1443
+ pipelineString += '\n\n';
1444
+ pipelineString += '```' + contentLanguage;
1445
+ pipelineString += '\n';
1446
+ pipelineString += spaceTrim(content);
1447
+ // <- TODO: [main] !!! Escape
1448
+ // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
1449
+ pipelineString += '\n';
1450
+ pipelineString += '```';
1451
+ pipelineString += '\n\n';
1452
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
1453
+ }
1454
+ }
1455
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1456
+ finally {
1457
+ try {
1458
+ if (tasks_1_1 && !tasks_1_1.done && (_c = tasks_1.return)) _c.call(tasks_1);
1459
+ }
1460
+ finally { if (e_3) throw e_3.error; }
1461
+ }
1462
+ return pipelineString;
1463
+ }
1464
+ /**
1465
+ * @private internal utility of `pipelineJsonToString`
1466
+ */
1467
+ function taskParameterJsonToString(taskParameterJson) {
1468
+ var name = taskParameterJson.name, description = taskParameterJson.description;
1469
+ var parameterString = "{".concat(name, "}");
1470
+ if (description) {
1471
+ parameterString = "".concat(parameterString, " ").concat(description);
1472
+ }
1473
+ return parameterString;
1474
+ }
1475
+ /**
1476
+ * TODO: [🛋] Implement new features and commands into `pipelineJsonToString` + `taskParameterJsonToString` , use `stringifyCommand`
1477
+ * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
1478
+ * TODO: [🏛] Maybe make some markdown builder
1479
+ * TODO: [🏛] Escape all
1480
+ * TODO: [🧠] Should be in generated .book.md file GENERATOR_WARNING
1481
+ */
1482
+
1483
1483
  /**
1484
1484
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
1485
1485
  *
@@ -2016,6 +2016,7 @@ function extractParameterNames(template) {
2016
2016
  /**
2017
2017
  * Unprepare just strips the preparation data of the pipeline
2018
2018
  *
2019
+ * @deprecated In future version this function will be removed or deprecated
2019
2020
  * @public exported from `@promptbook/core`
2020
2021
  */
2021
2022
  function unpreparePipeline(pipeline) {
@@ -7367,7 +7368,7 @@ var parameterCommandParser = {
7367
7368
  * Note: `$` is used to indicate that this function mutates given `pipelineJson`
7368
7369
  */
7369
7370
  $applyToPipelineJson: function (command, $pipelineJson) {
7370
- // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
7371
+ // Note: [🍣] Do nothing, its application is implemented separately in `precompilePipeline`
7371
7372
  },
7372
7373
  /**
7373
7374
  * Apply the PARAMETER command to the `pipelineJson`
@@ -7375,7 +7376,7 @@ var parameterCommandParser = {
7375
7376
  * Note: `$` is used to indicate that this function mutates given `taskJson`
7376
7377
  */
7377
7378
  $applyToTaskJson: function (command, $taskJson, $pipelineJson) {
7378
- // Note: [🍣] Do nothing, its application is implemented separately in `pipelineStringToJsonSync`
7379
+ // Note: [🍣] Do nothing, its application is implemented separately in `precompilePipeline`
7379
7380
  },
7380
7381
  /**
7381
7382
  * Converts the PARAMETER command back to string
@@ -7883,7 +7884,7 @@ var COMMANDS = [
7883
7884
  * @returns the parser for the command
7884
7885
  * @throws {UnexpectedError} if the parser is not found
7885
7886
  *
7886
- * @private within the pipelineStringToJson
7887
+ * @private within the compilePipeline
7887
7888
  */
7888
7889
  function getParserForCommand(command) {
7889
7890
  var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
@@ -7919,7 +7920,7 @@ function removeMarkdownFormatting(str) {
7919
7920
  * @returns parsed command object
7920
7921
  * @throws {ParseError} if the command is invalid
7921
7922
  *
7922
- * @private within the pipelineStringToJson
7923
+ * @private within the compilePipeline
7923
7924
  */
7924
7925
  function parseCommand(raw, usagePlace) {
7925
7926
  if (raw.includes('\n') || raw.includes('\r')) {
@@ -8334,7 +8335,7 @@ var QuickChatbotHla = {
8334
8335
  /**
8335
8336
  * All high-level abstractions
8336
8337
  *
8337
- * @private internal index of `pipelineStringToJsonSync` (= used for sync) and `preparePipeline` (= used for async)
8338
+ * @private internal index of `precompilePipeline` (= used for sync) and `preparePipeline` (= used for async)
8338
8339
  */
8339
8340
  var HIGH_LEVEL_ABSTRACTIONS = [
8340
8341
  ImplicitFormfactorHla,
@@ -8608,8 +8609,8 @@ function titleToName(value) {
8608
8609
  * Compile pipeline from string (markdown) format to JSON format synchronously
8609
8610
  *
8610
8611
  * Note: There are 3 similar functions:
8611
- * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
8612
- * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
8612
+ * - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
8613
+ * - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
8613
8614
  * - `preparePipeline` - just one step in the compilation process
8614
8615
  *
8615
8616
  * Note: This function does not validate logic of the pipeline only the parsing
@@ -8620,7 +8621,7 @@ function titleToName(value) {
8620
8621
  * @throws {ParseError} if the promptbook string is not valid
8621
8622
  * @public exported from `@promptbook/core`
8622
8623
  */
8623
- function pipelineStringToJsonSync(pipelineString) {
8624
+ function precompilePipeline(pipelineString) {
8624
8625
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
8625
8626
  var $pipelineJson = {
8626
8627
  title: DEFAULT_TITLE,
@@ -9040,7 +9041,7 @@ function pipelineStringToJsonSync(pipelineString) {
9040
9041
  // TODO: [🍙] Maybe do reorder of `$pipelineJson` here
9041
9042
  return exportJson({
9042
9043
  name: 'pipelineJson',
9043
- message: "Result of `pipelineStringToJsonSync`",
9044
+ message: "Result of `precompilePipeline`",
9044
9045
  order: ORDER_OF_PIPELINE_JSON,
9045
9046
  value: __assign({ formfactorName: 'GENERIC' }, $pipelineJson),
9046
9047
  });
@@ -9061,8 +9062,8 @@ function pipelineStringToJsonSync(pipelineString) {
9061
9062
  * Compile pipeline from string (markdown) format to JSON format
9062
9063
  *
9063
9064
  * Note: There are 3 similar functions:
9064
- * - `pipelineStringToJson` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
9065
- * - `pipelineStringToJsonSync` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
9065
+ * - `compilePipeline` **(preferred)** - which propperly compiles the promptbook and use embedding for external knowledge
9066
+ * - `precompilePipeline` - use only if you need to compile promptbook synchronously and it contains NO external knowledge
9066
9067
  * - `preparePipeline` - just one step in the compilation process
9067
9068
  *
9068
9069
  * Note: This function does not validate logic of the pipeline only the parsing
@@ -9075,13 +9076,13 @@ function pipelineStringToJsonSync(pipelineString) {
9075
9076
  * @throws {ParseError} if the promptbook string is not valid
9076
9077
  * @public exported from `@promptbook/core`
9077
9078
  */
9078
- function pipelineStringToJson(pipelineString, tools, options) {
9079
+ function compilePipeline(pipelineString, tools, options) {
9079
9080
  return __awaiter(this, void 0, void 0, function () {
9080
9081
  var pipelineJson;
9081
9082
  return __generator(this, function (_a) {
9082
9083
  switch (_a.label) {
9083
9084
  case 0:
9084
- pipelineJson = pipelineStringToJsonSync(pipelineString);
9085
+ pipelineJson = precompilePipeline(pipelineString);
9085
9086
  if (!(tools !== undefined && tools.llm !== undefined)) return [3 /*break*/, 2];
9086
9087
  return [4 /*yield*/, preparePipeline(pipelineJson, tools, options || {
9087
9088
  rootDirname: null,
@@ -9090,7 +9091,7 @@ function pipelineStringToJson(pipelineString, tools, options) {
9090
9091
  pipelineJson = _a.sent();
9091
9092
  _a.label = 2;
9092
9093
  case 2:
9093
- // Note: No need to use `$exportJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
9094
+ // Note: No need to use `$exportJson` because `precompilePipeline` and `preparePipeline` already do that
9094
9095
  return [2 /*return*/, pipelineJson];
9095
9096
  }
9096
9097
  });
@@ -10528,7 +10529,7 @@ function createCollectionFromDirectory(path, tools, options) {
10528
10529
  return [4 /*yield*/, readFile(fileName, 'utf-8')];
10529
10530
  case 2:
10530
10531
  pipelineString = (_e.sent());
10531
- return [4 /*yield*/, pipelineStringToJson(pipelineString, tools, {
10532
+ return [4 /*yield*/, compilePipeline(pipelineString, tools, {
10532
10533
  rootDirname: rootDirname,
10533
10534
  })];
10534
10535
  case 3: