@promptbook/node 0.61.0-17 → 0.61.0-19

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
@@ -203,200 +203,6 @@ TODO: !!! Just testing false-negative detection of [🟡][🟢][🔵][⚪] leak
203
203
  * TODO: [🔼] Export all to core
204
204
  */
205
205
 
206
- /**
207
- * @@@
208
- */
209
- function deepClone(objectValue) {
210
- return JSON.parse(JSON.stringify(objectValue));
211
- /*
212
- TODO: [🧠] Is there a better implementation?
213
- > const propertyNames = Object.getOwnPropertyNames(objectValue);
214
- > for (const propertyName of propertyNames) {
215
- > const value = (objectValue as really_any)[propertyName];
216
- > if (value && typeof value === 'object') {
217
- > deepClone(value);
218
- > }
219
- > }
220
- > return Object.assign({}, objectValue);
221
- */
222
- }
223
- /**
224
- * TODO: [🔼] Export from `@promptbook/utils`
225
- * TODO: [🧠] Is there a way how to meaningfully test this utility
226
- */
227
-
228
- /**
229
- * @@@
230
- *
231
- * TODO: [🔼] Export with addUsage
232
- */
233
- var ZERO_USAGE = deepFreeze({
234
- price: { value: 0 },
235
- input: {
236
- tokensCount: { value: 0 },
237
- charactersCount: { value: 0 },
238
- wordsCount: { value: 0 },
239
- sentencesCount: { value: 0 },
240
- linesCount: { value: 0 },
241
- paragraphsCount: { value: 0 },
242
- pagesCount: { value: 0 },
243
- },
244
- output: {
245
- tokensCount: { value: 0 },
246
- charactersCount: { value: 0 },
247
- wordsCount: { value: 0 },
248
- sentencesCount: { value: 0 },
249
- linesCount: { value: 0 },
250
- paragraphsCount: { value: 0 },
251
- pagesCount: { value: 0 },
252
- },
253
- });
254
- /**
255
- * Function `addUsage` will add multiple usages into one
256
- *
257
- * Note: If you provide 0 values, it returns ZERO_USAGE
258
- */
259
- function addUsage() {
260
- var usageItems = [];
261
- for (var _i = 0; _i < arguments.length; _i++) {
262
- usageItems[_i] = arguments[_i];
263
- }
264
- return usageItems.reduce(function (acc, item) {
265
- var e_1, _a, e_2, _b;
266
- var _c;
267
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
268
- try {
269
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
270
- var key = _e.value;
271
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
272
- //@ts-ignore
273
- if (item.input[key]) {
274
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
275
- //@ts-ignore
276
- acc.input[key].value += item.input[key].value || 0;
277
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
278
- //@ts-ignore
279
- if (item.input[key].isUncertain) {
280
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
281
- //@ts-ignore
282
- acc.input[key].isUncertain = true;
283
- }
284
- }
285
- }
286
- }
287
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
288
- finally {
289
- try {
290
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
291
- }
292
- finally { if (e_1) throw e_1.error; }
293
- }
294
- try {
295
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
296
- var key = _g.value;
297
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
298
- //@ts-ignore
299
- if (item.output[key]) {
300
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
301
- //@ts-ignore
302
- acc.output[key].value += item.output[key].value || 0;
303
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
304
- //@ts-ignore
305
- if (item.output[key].isUncertain) {
306
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
307
- //@ts-ignore
308
- acc.output[key].isUncertain = true;
309
- }
310
- }
311
- }
312
- }
313
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
314
- finally {
315
- try {
316
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
317
- }
318
- finally { if (e_2) throw e_2.error; }
319
- }
320
- return acc;
321
- }, deepClone(ZERO_USAGE));
322
- }
323
-
324
- /**
325
- * Async version of Array.forEach
326
- *
327
- * @param array - Array to iterate over
328
- * @param options - Options for the function
329
- * @param callbackfunction - Function to call for each item
330
- */
331
- function forEachAsync(array, options, callbackfunction) {
332
- return __awaiter(this, void 0, void 0, function () {
333
- var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
334
- var e_1, _d;
335
- return __generator(this, function (_e) {
336
- switch (_e.label) {
337
- case 0:
338
- _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
339
- index = 0;
340
- runningTasks = [];
341
- tasks = [];
342
- _loop_1 = function (item) {
343
- var currentIndex, task;
344
- return __generator(this, function (_f) {
345
- switch (_f.label) {
346
- case 0:
347
- currentIndex = index++;
348
- task = callbackfunction(item, currentIndex, array);
349
- tasks.push(task);
350
- runningTasks.push(task);
351
- /* not await */ Promise.resolve(task).then(function () {
352
- runningTasks = runningTasks.filter(function (t) { return t !== task; });
353
- });
354
- if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
355
- return [4 /*yield*/, Promise.race(runningTasks)];
356
- case 1:
357
- _f.sent();
358
- _f.label = 2;
359
- case 2: return [2 /*return*/];
360
- }
361
- });
362
- };
363
- _e.label = 1;
364
- case 1:
365
- _e.trys.push([1, 6, 7, 8]);
366
- _b = __values(array), _c = _b.next();
367
- _e.label = 2;
368
- case 2:
369
- if (!!_c.done) return [3 /*break*/, 5];
370
- item = _c.value;
371
- return [5 /*yield**/, _loop_1(item)];
372
- case 3:
373
- _e.sent();
374
- _e.label = 4;
375
- case 4:
376
- _c = _b.next();
377
- return [3 /*break*/, 2];
378
- case 5: return [3 /*break*/, 8];
379
- case 6:
380
- e_1_1 = _e.sent();
381
- e_1 = { error: e_1_1 };
382
- return [3 /*break*/, 8];
383
- case 7:
384
- try {
385
- if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
386
- }
387
- finally { if (e_1) throw e_1.error; }
388
- return [7 /*endfinally*/];
389
- case 8: return [4 /*yield*/, Promise.all(tasks)];
390
- case 9:
391
- _e.sent();
392
- return [2 /*return*/];
393
- }
394
- });
395
- });
396
- }
397
-
398
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-16",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-16",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-16",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-16",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-16",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-16",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-16",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-16",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
399
-
400
206
  /**
401
207
  * Prettify the html code
402
208
  *
@@ -619,26 +425,220 @@ function pipelineJsonToString(pipelineJson) {
619
425
  try {
620
426
  if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
621
427
  }
622
- finally { if (e_3) throw e_3.error; }
623
- }
624
- return pipelineString;
428
+ finally { if (e_3) throw e_3.error; }
429
+ }
430
+ return pipelineString;
431
+ }
432
+ /**
433
+ * @private internal util of pipelineJsonToString
434
+ */
435
+ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
436
+ var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
437
+ var parameterString = "{".concat(name, "}");
438
+ if (description) {
439
+ parameterString = "".concat(parameterString, " ").concat(description);
440
+ }
441
+ return parameterString;
442
+ }
443
+ /**
444
+ * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
445
+ * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
446
+ * TODO: Escape all
447
+ */
448
+
449
+ /**
450
+ * @@@
451
+ */
452
+ function deepClone(objectValue) {
453
+ return JSON.parse(JSON.stringify(objectValue));
454
+ /*
455
+ TODO: [🧠] Is there a better implementation?
456
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
457
+ > for (const propertyName of propertyNames) {
458
+ > const value = (objectValue as really_any)[propertyName];
459
+ > if (value && typeof value === 'object') {
460
+ > deepClone(value);
461
+ > }
462
+ > }
463
+ > return Object.assign({}, objectValue);
464
+ */
465
+ }
466
+ /**
467
+ * TODO: [🔼] Export from `@promptbook/utils`
468
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
469
+ */
470
+
471
+ /**
472
+ * @@@
473
+ *
474
+ * TODO: [🔼] Export with addUsage
475
+ */
476
+ var ZERO_USAGE = deepFreeze({
477
+ price: { value: 0 },
478
+ input: {
479
+ tokensCount: { value: 0 },
480
+ charactersCount: { value: 0 },
481
+ wordsCount: { value: 0 },
482
+ sentencesCount: { value: 0 },
483
+ linesCount: { value: 0 },
484
+ paragraphsCount: { value: 0 },
485
+ pagesCount: { value: 0 },
486
+ },
487
+ output: {
488
+ tokensCount: { value: 0 },
489
+ charactersCount: { value: 0 },
490
+ wordsCount: { value: 0 },
491
+ sentencesCount: { value: 0 },
492
+ linesCount: { value: 0 },
493
+ paragraphsCount: { value: 0 },
494
+ pagesCount: { value: 0 },
495
+ },
496
+ });
497
+ /**
498
+ * Function `addUsage` will add multiple usages into one
499
+ *
500
+ * Note: If you provide 0 values, it returns ZERO_USAGE
501
+ */
502
+ function addUsage() {
503
+ var usageItems = [];
504
+ for (var _i = 0; _i < arguments.length; _i++) {
505
+ usageItems[_i] = arguments[_i];
506
+ }
507
+ return usageItems.reduce(function (acc, item) {
508
+ var e_1, _a, e_2, _b;
509
+ var _c;
510
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
511
+ try {
512
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
513
+ var key = _e.value;
514
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
515
+ //@ts-ignore
516
+ if (item.input[key]) {
517
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
518
+ //@ts-ignore
519
+ acc.input[key].value += item.input[key].value || 0;
520
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
521
+ //@ts-ignore
522
+ if (item.input[key].isUncertain) {
523
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
524
+ //@ts-ignore
525
+ acc.input[key].isUncertain = true;
526
+ }
527
+ }
528
+ }
529
+ }
530
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
531
+ finally {
532
+ try {
533
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
534
+ }
535
+ finally { if (e_1) throw e_1.error; }
536
+ }
537
+ try {
538
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
539
+ var key = _g.value;
540
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
541
+ //@ts-ignore
542
+ if (item.output[key]) {
543
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
544
+ //@ts-ignore
545
+ acc.output[key].value += item.output[key].value || 0;
546
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
547
+ //@ts-ignore
548
+ if (item.output[key].isUncertain) {
549
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
550
+ //@ts-ignore
551
+ acc.output[key].isUncertain = true;
552
+ }
553
+ }
554
+ }
555
+ }
556
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
557
+ finally {
558
+ try {
559
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
560
+ }
561
+ finally { if (e_2) throw e_2.error; }
562
+ }
563
+ return acc;
564
+ }, deepClone(ZERO_USAGE));
625
565
  }
566
+
626
567
  /**
627
- * @private internal util of pipelineJsonToString
568
+ * Async version of Array.forEach
569
+ *
570
+ * @param array - Array to iterate over
571
+ * @param options - Options for the function
572
+ * @param callbackfunction - Function to call for each item
628
573
  */
629
- function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
630
- var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
631
- var parameterString = "{".concat(name, "}");
632
- if (description) {
633
- parameterString = "".concat(parameterString, " ").concat(description);
634
- }
635
- return parameterString;
574
+ function forEachAsync(array, options, callbackfunction) {
575
+ return __awaiter(this, void 0, void 0, function () {
576
+ var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
577
+ var e_1, _d;
578
+ return __generator(this, function (_e) {
579
+ switch (_e.label) {
580
+ case 0:
581
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
582
+ index = 0;
583
+ runningTasks = [];
584
+ tasks = [];
585
+ _loop_1 = function (item) {
586
+ var currentIndex, task;
587
+ return __generator(this, function (_f) {
588
+ switch (_f.label) {
589
+ case 0:
590
+ currentIndex = index++;
591
+ task = callbackfunction(item, currentIndex, array);
592
+ tasks.push(task);
593
+ runningTasks.push(task);
594
+ /* not await */ Promise.resolve(task).then(function () {
595
+ runningTasks = runningTasks.filter(function (t) { return t !== task; });
596
+ });
597
+ if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
598
+ return [4 /*yield*/, Promise.race(runningTasks)];
599
+ case 1:
600
+ _f.sent();
601
+ _f.label = 2;
602
+ case 2: return [2 /*return*/];
603
+ }
604
+ });
605
+ };
606
+ _e.label = 1;
607
+ case 1:
608
+ _e.trys.push([1, 6, 7, 8]);
609
+ _b = __values(array), _c = _b.next();
610
+ _e.label = 2;
611
+ case 2:
612
+ if (!!_c.done) return [3 /*break*/, 5];
613
+ item = _c.value;
614
+ return [5 /*yield**/, _loop_1(item)];
615
+ case 3:
616
+ _e.sent();
617
+ _e.label = 4;
618
+ case 4:
619
+ _c = _b.next();
620
+ return [3 /*break*/, 2];
621
+ case 5: return [3 /*break*/, 8];
622
+ case 6:
623
+ e_1_1 = _e.sent();
624
+ e_1 = { error: e_1_1 };
625
+ return [3 /*break*/, 8];
626
+ case 7:
627
+ try {
628
+ if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
629
+ }
630
+ finally { if (e_1) throw e_1.error; }
631
+ return [7 /*endfinally*/];
632
+ case 8: return [4 /*yield*/, Promise.all(tasks)];
633
+ case 9:
634
+ _e.sent();
635
+ return [2 /*return*/];
636
+ }
637
+ });
638
+ });
636
639
  }
637
- /**
638
- * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
639
- * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
640
- * TODO: Escape all
641
- */
640
+
641
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.61.0-18",parameters:[{name:"content",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledge",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"knowledge"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-18",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.61.0-18",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",dependentParameterNames:["content"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-18",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.61.0-18",parameters:[{name:"content",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},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> {content}",expectations:{words:{min:1,max:8}},dependentParameterNames:["content"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-18",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.61.0-18",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}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\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### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[{id:1,promptbookVersion:"0.61.0-18",modelUsage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
642
642
 
643
643
  /**
644
644
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -1071,79 +1071,100 @@ var ReferenceError$1 = /** @class */ (function (_super) {
1071
1071
  }(Error));
1072
1072
 
1073
1073
  /**
1074
- * Library of promptbooks that groups together promptbooks for an application.
1075
- * This implementation is a very thin wrapper around the Array / Map of promptbooks.
1074
+ * Unprepare just strips the preparation data of the pipeline
1075
+ */
1076
+ function unpreparePipeline(pipeline) {
1077
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
1078
+ personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1079
+ knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1080
+ return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1081
+ }
1082
+ /**
1083
+ * TODO: [🔼] !!! Export via `@promptbook/core`
1084
+ * TODO: Write tests for `preparePipeline`
1085
+ */
1086
+
1087
+ /**
1088
+ * Library of pipelines that groups together pipelines for an application.
1089
+ * This implementation is a very thin wrapper around the Array / Map of pipelines.
1076
1090
  *
1077
1091
  * @private use `createCollectionFromJson` instead
1078
- * @see https://github.com/webgptorg/promptbook#promptbook-collection
1092
+ * @see https://github.com/webgptorg/pipeline#pipeline-collection
1079
1093
  */
1080
1094
  var SimplePipelineCollection = /** @class */ (function () {
1081
1095
  /**
1082
- * Constructs a pipeline collection from promptbooks
1096
+ * Constructs a pipeline collection from pipelines
1083
1097
  *
1084
- * @param promptbooks @@@
1098
+ * @param pipelines @@@
1085
1099
  *
1086
1100
  * @private Use instead `createCollectionFromJson`
1087
- * Note: During the construction logic of all promptbooks are validated
1101
+ * Note: During the construction logic of all pipelines are validated
1088
1102
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
1089
1103
  */
1090
1104
  function SimplePipelineCollection() {
1091
1105
  var e_1, _a;
1092
- var promptbooks = [];
1106
+ var pipelines = [];
1093
1107
  for (var _i = 0; _i < arguments.length; _i++) {
1094
- promptbooks[_i] = arguments[_i];
1108
+ pipelines[_i] = arguments[_i];
1095
1109
  }
1096
1110
  this.collection = new Map();
1097
1111
  try {
1098
- for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
1099
- var promptbook = promptbooks_1_1.value;
1100
- if (promptbook.pipelineUrl === undefined) {
1101
- throw new ReferenceError$1(spaceTrim$1("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n File:\n ").concat(promptbook.sourceFile || 'Unknown', "\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the pipeline collection\n\n ")));
1112
+ for (var pipelines_1 = __values(pipelines), pipelines_1_1 = pipelines_1.next(); !pipelines_1_1.done; pipelines_1_1 = pipelines_1.next()) {
1113
+ var pipeline = pipelines_1_1.value;
1114
+ // TODO: [👠] DRY
1115
+ if (pipeline.pipelineUrl === undefined) {
1116
+ throw new ReferenceError$1(spaceTrim$1("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
1102
1117
  }
1103
- validatePipeline(promptbook);
1118
+ // Note: [🐨]
1119
+ validatePipeline(pipeline);
1120
+ // TODO: [🦄] DRY
1104
1121
  // Note: [🦄]
1105
- if (this.collection.has(promptbook.pipelineUrl) &&
1106
- pipelineJsonToString(promptbook) !== pipelineJsonToString(this.collection.get(promptbook.pipelineUrl))) {
1107
- var existing = this.collection.get(promptbook.pipelineUrl);
1108
- throw new ReferenceError$1(spaceTrim$1("\n Promptbook with URL \"".concat(promptbook.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(promptbook.sourceFile || 'Unknown', "\n\n Note: Promptbooks with the same URL are not allowed\n Only exepction is when the promptbooks are identical\n\n ")));
1122
+ if (
1123
+ // TODO: [🐽]
1124
+ this.collection.has(pipeline.pipelineUrl) &&
1125
+ pipelineJsonToString(unpreparePipeline(pipeline)) !==
1126
+ pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1127
+ var existing = this.collection.get(pipeline.pipelineUrl);
1128
+ throw new ReferenceError$1(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
1109
1129
  }
1110
- this.collection.set(promptbook.pipelineUrl, promptbook);
1130
+ // Note: [🧠] Overwrite existing pipeline with the same URL
1131
+ this.collection.set(pipeline.pipelineUrl, pipeline);
1111
1132
  }
1112
1133
  }
1113
1134
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
1114
1135
  finally {
1115
1136
  try {
1116
- if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
1137
+ if (pipelines_1_1 && !pipelines_1_1.done && (_a = pipelines_1.return)) _a.call(pipelines_1);
1117
1138
  }
1118
1139
  finally { if (e_1) throw e_1.error; }
1119
1140
  }
1120
1141
  }
1121
1142
  /**
1122
- * Gets all promptbooks in the collection
1143
+ * Gets all pipelines in the collection
1123
1144
  */
1124
1145
  SimplePipelineCollection.prototype.listPipelines = function () {
1125
1146
  return Array.from(this.collection.keys());
1126
1147
  };
1127
1148
  /**
1128
- * Gets promptbook by its URL
1149
+ * Gets pipeline by its URL
1129
1150
  *
1130
1151
  * Note: This is not a direct fetching from the URL, but a lookup in the collection
1131
1152
  */
1132
1153
  SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
1133
1154
  var _this = this;
1134
- var promptbook = this.collection.get(url);
1135
- if (!promptbook) {
1155
+ var pipeline = this.collection.get(url);
1156
+ if (!pipeline) {
1136
1157
  if (this.listPipelines().length === 0) {
1137
- throw new NotFoundError(spaceTrim$1("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
1158
+ throw new NotFoundError(spaceTrim$1("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
1138
1159
  }
1139
- throw new NotFoundError(spaceTrim$1(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPipelines()
1160
+ throw new NotFoundError(spaceTrim$1(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
1140
1161
  .map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
1141
1162
  .join('\n')), "\n\n "); }));
1142
1163
  }
1143
- return promptbook;
1164
+ return pipeline;
1144
1165
  };
1145
1166
  /**
1146
- * Checks whether given prompt was defined in any promptbook in the collection
1167
+ * Checks whether given prompt was defined in any pipeline in the collection
1147
1168
  */
1148
1169
  SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
1149
1170
  return true;
@@ -1546,39 +1567,6 @@ function assertsExecutionSuccessful(executionResult) {
1546
1567
  * TODO: [🧠] Can this return type be better typed than void
1547
1568
  */
1548
1569
 
1549
- /**
1550
- * Create difference set of two sets.
1551
- *
1552
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
1553
- */
1554
- function difference(a, b, isEqual) {
1555
- var e_1, _a;
1556
- if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
1557
- var diff = new Set();
1558
- var _loop_1 = function (itemA) {
1559
- if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
1560
- diff.add(itemA);
1561
- }
1562
- };
1563
- try {
1564
- for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
1565
- var itemA = _c.value;
1566
- _loop_1(itemA);
1567
- }
1568
- }
1569
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1570
- finally {
1571
- try {
1572
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1573
- }
1574
- finally { if (e_1) throw e_1.error; }
1575
- }
1576
- return diff;
1577
- }
1578
- /**
1579
- * TODO: [🧠][💯] Maybe also implement symmetricDifference
1580
- */
1581
-
1582
1570
  /**
1583
1571
  * Parses the template and returns the list of all parameter names
1584
1572
  *
@@ -1712,46 +1700,6 @@ function extractParametersFromPromptTemplate(promptTemplate) {
1712
1700
  * TODO: [🔣] If script require contentLanguage
1713
1701
  */
1714
1702
 
1715
- /**
1716
- * Creates a new set with all elements that are present in either set
1717
- *
1718
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
1719
- */
1720
- function union() {
1721
- var e_1, _a, e_2, _b;
1722
- var sets = [];
1723
- for (var _i = 0; _i < arguments.length; _i++) {
1724
- sets[_i] = arguments[_i];
1725
- }
1726
- var union = new Set();
1727
- try {
1728
- for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
1729
- var set = sets_1_1.value;
1730
- try {
1731
- for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
1732
- var item = _d.value;
1733
- union.add(item);
1734
- }
1735
- }
1736
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1737
- finally {
1738
- try {
1739
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1740
- }
1741
- finally { if (e_2) throw e_2.error; }
1742
- }
1743
- }
1744
- }
1745
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1746
- finally {
1747
- try {
1748
- if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
1749
- }
1750
- finally { if (e_1) throw e_1.error; }
1751
- }
1752
- return union;
1753
- }
1754
-
1755
1703
  /**
1756
1704
  * This error occurs when some expectation is not met in the execution of the pipeline
1757
1705
  *
@@ -1918,7 +1866,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
1918
1866
  throw new PipelineExecutionError(spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors.map(function (error) { return "- ".concat(error.name || 'Error', ": ").concat(error.message); }).join('\n')), "\n\n "); }));
1919
1867
  }
1920
1868
  else {
1921
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n No execution tools available for model variant \"".concat(prompt.modelRequirements.modelVariant, "\".\n\n tl;dr\n\n You have provided no LLM Execution Tools that support model variant \"").concat(prompt.modelRequirements.modelVariant, ":\n ").concat(block(_this.llmExecutionTools
1869
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
1922
1870
  .map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
1923
1871
  .join('\n')), "\n\n "); }));
1924
1872
  }
@@ -1997,7 +1945,7 @@ function joinLlmExecutionTools() {
1997
1945
  llmExecutionTools[_i] = arguments[_i];
1998
1946
  }
1999
1947
  if (llmExecutionTools.length === 0) {
2000
- var warningMessage = spaceTrim("\n You have provided no LLM Execution Tools.\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
1948
+ var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
2001
1949
  // TODO: [🟥] Detect browser / node and make it colorfull
2002
1950
  console.warn(warningMessage);
2003
1951
  /*
@@ -2157,10 +2105,83 @@ function replaceParameters(template, parameters) {
2157
2105
  return replacedTemplate;
2158
2106
  }
2159
2107
 
2108
+ /**
2109
+ * Create difference set of two sets.
2110
+ *
2111
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2112
+ */
2113
+ function difference(a, b, isEqual) {
2114
+ var e_1, _a;
2115
+ if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
2116
+ var diff = new Set();
2117
+ var _loop_1 = function (itemA) {
2118
+ if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
2119
+ diff.add(itemA);
2120
+ }
2121
+ };
2122
+ try {
2123
+ for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
2124
+ var itemA = _c.value;
2125
+ _loop_1(itemA);
2126
+ }
2127
+ }
2128
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2129
+ finally {
2130
+ try {
2131
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2132
+ }
2133
+ finally { if (e_1) throw e_1.error; }
2134
+ }
2135
+ return diff;
2136
+ }
2137
+ /**
2138
+ * TODO: [🧠][💯] Maybe also implement symmetricDifference
2139
+ */
2140
+
2141
+ /**
2142
+ * Creates a new set with all elements that are present in either set
2143
+ *
2144
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2145
+ */
2146
+ function union() {
2147
+ var e_1, _a, e_2, _b;
2148
+ var sets = [];
2149
+ for (var _i = 0; _i < arguments.length; _i++) {
2150
+ sets[_i] = arguments[_i];
2151
+ }
2152
+ var union = new Set();
2153
+ try {
2154
+ for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
2155
+ var set = sets_1_1.value;
2156
+ try {
2157
+ for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
2158
+ var item = _d.value;
2159
+ union.add(item);
2160
+ }
2161
+ }
2162
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2163
+ finally {
2164
+ try {
2165
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2166
+ }
2167
+ finally { if (e_2) throw e_2.error; }
2168
+ }
2169
+ }
2170
+ }
2171
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2172
+ finally {
2173
+ try {
2174
+ if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
2175
+ }
2176
+ finally { if (e_1) throw e_1.error; }
2177
+ }
2178
+ return union;
2179
+ }
2180
+
2160
2181
  /**
2161
2182
  * The version of the Promptbook library
2162
2183
  */
2163
- var PROMPTBOOK_VERSION = '0.61.0-16';
2184
+ var PROMPTBOOK_VERSION = '0.61.0-18';
2164
2185
  // TODO: !!!! List here all the versions and annotate + put into script
2165
2186
 
2166
2187
  /**
@@ -2290,7 +2311,7 @@ function createPipelineExecutor(options) {
2290
2311
  pipeline = rawPipeline;
2291
2312
  }
2292
2313
  else {
2293
- console.warn(spaceTrim$1("\n Pipeline is not prepared\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n "));
2314
+ console.warn(spaceTrim$1("\n Pipeline ".concat(rawPipeline.pipelineUrl || rawPipeline.sourceFile || rawPipeline.title, " is not prepared\n\n It will be prepared ad-hoc before the first execution\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
2294
2315
  }
2295
2316
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2296
2317
  function getContextForTemplate(// <- TODO: [🧠][🥜]
@@ -5384,11 +5405,11 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
5384
5405
  }
5385
5406
 
5386
5407
  /**
5387
- * Constructs Promptbook from given directory
5408
+ * Constructs Pipeline from given directory
5388
5409
  *
5389
5410
  * Note: Works only in Node.js environment because it reads the file system
5390
5411
  *
5391
- * @param path - path to the directory with promptbooks
5412
+ * @param path - path to the directory with pipelines
5392
5413
  * @param options - Misc options for the collection
5393
5414
  * @returns PipelineCollection
5394
5415
  */
@@ -5418,20 +5439,31 @@ function createCollectionFromDirectory(path, options) {
5418
5439
  }
5419
5440
  _a = options || {}, _b = _a.isRecursive, isRecursive = _b === void 0 ? true : _b, _c = _a.isVerbose, isVerbose = _c === void 0 ? false : _c, _d = _a.isLazyLoaded, isLazyLoaded = _d === void 0 ? false : _d, _e = _a.isCrashedOnError, isCrashedOnError = _e === void 0 ? true : _e;
5420
5441
  collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
5421
- var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
5442
+ var fileNames, collection, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
5422
5443
  var e_1, _a;
5423
5444
  return __generator(this, function (_b) {
5424
5445
  switch (_b.label) {
5425
5446
  case 0:
5426
5447
  if (isVerbose) {
5427
- console.info("Creating pipeline collection from path ".concat(path.split('\\').join('/')));
5448
+ console.info(colors.cyan("Creating pipeline collection from path ".concat(path.split('\\').join('/'))));
5428
5449
  }
5429
5450
  return [4 /*yield*/, listAllFiles(path, isRecursive)];
5430
5451
  case 1:
5431
5452
  fileNames = _b.sent();
5432
- promptbooks = [];
5453
+ // Note: First load all .ptbk.json and then .ptbk.md files
5454
+ // .ptbk.json can be prepared so it is faster to load
5455
+ fileNames.sort(function (a, b) {
5456
+ if (a.endsWith('.ptbk.json') && b.endsWith('.ptbk.md')) {
5457
+ return -1;
5458
+ }
5459
+ if (a.endsWith('.ptbk.md') && b.endsWith('.ptbk.json')) {
5460
+ return 1;
5461
+ }
5462
+ return 0;
5463
+ });
5464
+ collection = new Map();
5433
5465
  _loop_1 = function (fileName) {
5434
- var sourceFile, promptbook, pipelineString, _c, _d, error_1, wrappedErrorMessage;
5466
+ var sourceFile, pipeline, pipelineString, _c, _d, existing, error_1, wrappedErrorMessage;
5435
5467
  return __generator(this, function (_e) {
5436
5468
  switch (_e.label) {
5437
5469
  case 0:
@@ -5439,53 +5471,67 @@ function createCollectionFromDirectory(path, options) {
5439
5471
  _e.label = 1;
5440
5472
  case 1:
5441
5473
  _e.trys.push([1, 8, , 9]);
5442
- promptbook = null;
5474
+ pipeline = null;
5443
5475
  if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 4];
5444
5476
  return [4 /*yield*/, readFile(fileName, 'utf8')];
5445
5477
  case 2:
5446
5478
  pipelineString = (_e.sent());
5447
5479
  return [4 /*yield*/, pipelineStringToJson(pipelineString, options)];
5448
5480
  case 3:
5449
- promptbook = _e.sent();
5450
- promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
5481
+ pipeline = _e.sent();
5482
+ pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
5451
5483
  return [3 /*break*/, 7];
5452
5484
  case 4:
5453
5485
  if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 6];
5454
- if (isVerbose) {
5455
- console.info("Loading ".concat(fileName.split('\\').join('/')));
5456
- }
5457
5486
  _d = (_c = JSON).parse;
5458
5487
  return [4 /*yield*/, readFile(fileName, 'utf8')];
5459
5488
  case 5:
5460
5489
  // TODO: Handle non-valid JSON files
5461
- promptbook = _d.apply(_c, [_e.sent()]);
5490
+ pipeline = _d.apply(_c, [_e.sent()]);
5462
5491
  // TODO: [🌗]
5463
- promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
5492
+ pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
5464
5493
  return [3 /*break*/, 7];
5465
5494
  case 6:
5466
5495
  if (isVerbose) {
5467
- console.info("Skipping file ".concat(fileName.split('\\').join('/')));
5496
+ console.info(colors.gray("Skipping file ".concat(fileName.split('\\').join('/'))));
5468
5497
  }
5469
5498
  _e.label = 7;
5470
5499
  case 7:
5471
5500
  // ---
5472
- if (promptbook !== null) {
5473
- if (!promptbook.pipelineUrl) {
5501
+ if (pipeline !== null) {
5502
+ // TODO: [👠] DRY
5503
+ if (pipeline.pipelineUrl === undefined) {
5474
5504
  if (isVerbose) {
5475
- console.info("Not loading ".concat(fileName.split('\\').join('/'), " - missing URL"));
5505
+ console.info(colors.red("Can not load pipeline from ".concat(fileName
5506
+ .split('\\')
5507
+ .join('/'), " because of missing URL")));
5476
5508
  }
5477
5509
  }
5478
5510
  else {
5479
- if (isVerbose) {
5480
- console.info("Loading ".concat(fileName.split('\\').join('/')));
5511
+ // Note: [🐨] Pipeline is checked multiple times
5512
+ // TODO: Maybe once is enough BUT be sure to check it - better to check it multiple times than not at all
5513
+ validatePipeline(pipeline);
5514
+ if (
5515
+ // TODO: [🐽] comparePipelines(pipeline1,pipeline2): 'IDENTICAL' |'IDENTICAL_UNPREPARED' | 'IDENTICAL_INTERFACE' | 'DIFFERENT'
5516
+ !collection.has(pipeline.pipelineUrl)) {
5517
+ if (isVerbose) {
5518
+ console.info(colors.gray("Loaded pipeline ".concat(fileName.split('\\').join('/'), "\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060")));
5519
+ }
5520
+ // Note: [🦄] Pipeline with same url uniqueness will be double-checked automatically in SimplePipelineCollection
5521
+ collection.set(pipeline.pipelineUrl, pipeline);
5481
5522
  }
5482
- if (!isCrashedOnError) {
5483
- // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
5484
- // But be handled in current try-catch block
5485
- validatePipeline(promptbook);
5523
+ else if (pipelineJsonToString(unpreparePipeline(pipeline)) ===
5524
+ pipelineJsonToString(unpreparePipeline(collection.get(pipeline.pipelineUrl)))) {
5525
+ if (isVerbose) {
5526
+ console.info(colors.gray("Skipped pipeline ".concat(fileName
5527
+ .split('\\')
5528
+ .join('/'), " \u2013\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060 identical pipeline in the collection")));
5529
+ }
5530
+ }
5531
+ else {
5532
+ existing = collection.get(pipeline.pipelineUrl);
5533
+ throw new ReferenceError(spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
5486
5534
  }
5487
- // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePipelineCollection
5488
- promptbooks.push(promptbook);
5489
5535
  }
5490
5536
  }
5491
5537
  return [3 /*break*/, 9];
@@ -5494,7 +5540,7 @@ function createCollectionFromDirectory(path, options) {
5494
5540
  if (!(error_1 instanceof Error)) {
5495
5541
  throw error_1;
5496
5542
  }
5497
- wrappedErrorMessage = spaceTrim(function (block) { return "\n Error during loading pipeline from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
5543
+ wrappedErrorMessage = spaceTrim(function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
5498
5544
  if (isCrashedOnError) {
5499
5545
  throw new CollectionError(wrappedErrorMessage);
5500
5546
  }
@@ -5531,7 +5577,7 @@ function createCollectionFromDirectory(path, options) {
5531
5577
  }
5532
5578
  finally { if (e_1) throw e_1.error; }
5533
5579
  return [7 /*endfinally*/];
5534
- case 9: return [2 /*return*/, promptbooks];
5580
+ case 9: return [2 /*return*/, Array.from(collection.values())];
5535
5581
  }
5536
5582
  });
5537
5583
  }); });
@@ -5605,8 +5651,8 @@ function listAllFiles(path, isRecursive) {
5605
5651
  });
5606
5652
  }
5607
5653
  /**
5608
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
5609
- * Note: [🟢] This code should never be published outside of `@promptbook/node`
5654
+ * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json pipelines
5655
+ * Note: [🟢] This code should never be published outside of `@pipeline/node`
5610
5656
  */
5611
5657
 
5612
5658
  /**