@promptbook/cli 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/umd/index.umd.js CHANGED
@@ -154,7 +154,7 @@
154
154
  /**
155
155
  * The version of the Promptbook library
156
156
  */
157
- var PROMPTBOOK_VERSION = '0.61.0-16';
157
+ var PROMPTBOOK_VERSION = '0.61.0-18';
158
158
  // TODO: !!!! List here all the versions and annotate + put into script
159
159
 
160
160
  /**
@@ -304,200 +304,6 @@
304
304
  * TODO: [🔼] Export all to core
305
305
  */
306
306
 
307
- /**
308
- * @@@
309
- */
310
- function deepClone(objectValue) {
311
- return JSON.parse(JSON.stringify(objectValue));
312
- /*
313
- TODO: [🧠] Is there a better implementation?
314
- > const propertyNames = Object.getOwnPropertyNames(objectValue);
315
- > for (const propertyName of propertyNames) {
316
- > const value = (objectValue as really_any)[propertyName];
317
- > if (value && typeof value === 'object') {
318
- > deepClone(value);
319
- > }
320
- > }
321
- > return Object.assign({}, objectValue);
322
- */
323
- }
324
- /**
325
- * TODO: [🔼] Export from `@promptbook/utils`
326
- * TODO: [🧠] Is there a way how to meaningfully test this utility
327
- */
328
-
329
- /**
330
- * @@@
331
- *
332
- * TODO: [🔼] Export with addUsage
333
- */
334
- var ZERO_USAGE = deepFreeze({
335
- price: { value: 0 },
336
- input: {
337
- tokensCount: { value: 0 },
338
- charactersCount: { value: 0 },
339
- wordsCount: { value: 0 },
340
- sentencesCount: { value: 0 },
341
- linesCount: { value: 0 },
342
- paragraphsCount: { value: 0 },
343
- pagesCount: { value: 0 },
344
- },
345
- output: {
346
- tokensCount: { value: 0 },
347
- charactersCount: { value: 0 },
348
- wordsCount: { value: 0 },
349
- sentencesCount: { value: 0 },
350
- linesCount: { value: 0 },
351
- paragraphsCount: { value: 0 },
352
- pagesCount: { value: 0 },
353
- },
354
- });
355
- /**
356
- * Function `addUsage` will add multiple usages into one
357
- *
358
- * Note: If you provide 0 values, it returns ZERO_USAGE
359
- */
360
- function addUsage() {
361
- var usageItems = [];
362
- for (var _i = 0; _i < arguments.length; _i++) {
363
- usageItems[_i] = arguments[_i];
364
- }
365
- return usageItems.reduce(function (acc, item) {
366
- var e_1, _a, e_2, _b;
367
- var _c;
368
- acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
369
- try {
370
- for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
371
- var key = _e.value;
372
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
373
- //@ts-ignore
374
- if (item.input[key]) {
375
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
376
- //@ts-ignore
377
- acc.input[key].value += item.input[key].value || 0;
378
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
379
- //@ts-ignore
380
- if (item.input[key].isUncertain) {
381
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
382
- //@ts-ignore
383
- acc.input[key].isUncertain = true;
384
- }
385
- }
386
- }
387
- }
388
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
389
- finally {
390
- try {
391
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
392
- }
393
- finally { if (e_1) throw e_1.error; }
394
- }
395
- try {
396
- for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
397
- var key = _g.value;
398
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
399
- //@ts-ignore
400
- if (item.output[key]) {
401
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
402
- //@ts-ignore
403
- acc.output[key].value += item.output[key].value || 0;
404
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
405
- //@ts-ignore
406
- if (item.output[key].isUncertain) {
407
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
408
- //@ts-ignore
409
- acc.output[key].isUncertain = true;
410
- }
411
- }
412
- }
413
- }
414
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
415
- finally {
416
- try {
417
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
418
- }
419
- finally { if (e_2) throw e_2.error; }
420
- }
421
- return acc;
422
- }, deepClone(ZERO_USAGE));
423
- }
424
-
425
- /**
426
- * Async version of Array.forEach
427
- *
428
- * @param array - Array to iterate over
429
- * @param options - Options for the function
430
- * @param callbackfunction - Function to call for each item
431
- */
432
- function forEachAsync(array, options, callbackfunction) {
433
- return __awaiter(this, void 0, void 0, function () {
434
- var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
435
- var e_1, _d;
436
- return __generator(this, function (_e) {
437
- switch (_e.label) {
438
- case 0:
439
- _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
440
- index = 0;
441
- runningTasks = [];
442
- tasks = [];
443
- _loop_1 = function (item) {
444
- var currentIndex, task;
445
- return __generator(this, function (_f) {
446
- switch (_f.label) {
447
- case 0:
448
- currentIndex = index++;
449
- task = callbackfunction(item, currentIndex, array);
450
- tasks.push(task);
451
- runningTasks.push(task);
452
- /* not await */ Promise.resolve(task).then(function () {
453
- runningTasks = runningTasks.filter(function (t) { return t !== task; });
454
- });
455
- if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
456
- return [4 /*yield*/, Promise.race(runningTasks)];
457
- case 1:
458
- _f.sent();
459
- _f.label = 2;
460
- case 2: return [2 /*return*/];
461
- }
462
- });
463
- };
464
- _e.label = 1;
465
- case 1:
466
- _e.trys.push([1, 6, 7, 8]);
467
- _b = __values(array), _c = _b.next();
468
- _e.label = 2;
469
- case 2:
470
- if (!!_c.done) return [3 /*break*/, 5];
471
- item = _c.value;
472
- return [5 /*yield**/, _loop_1(item)];
473
- case 3:
474
- _e.sent();
475
- _e.label = 4;
476
- case 4:
477
- _c = _b.next();
478
- return [3 /*break*/, 2];
479
- case 5: return [3 /*break*/, 8];
480
- case 6:
481
- e_1_1 = _e.sent();
482
- e_1 = { error: e_1_1 };
483
- return [3 /*break*/, 8];
484
- case 7:
485
- try {
486
- if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
487
- }
488
- finally { if (e_1) throw e_1.error; }
489
- return [7 /*endfinally*/];
490
- case 8: return [4 /*yield*/, Promise.all(tasks)];
491
- case 9:
492
- _e.sent();
493
- return [2 /*return*/];
494
- }
495
- });
496
- });
497
- }
498
-
499
- 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"}];
500
-
501
307
  /**
502
308
  * Prettify the html code
503
309
  *
@@ -720,26 +526,220 @@
720
526
  try {
721
527
  if (promptTemplates_1_1 && !promptTemplates_1_1.done && (_c = promptTemplates_1.return)) _c.call(promptTemplates_1);
722
528
  }
723
- finally { if (e_3) throw e_3.error; }
724
- }
725
- return pipelineString;
529
+ finally { if (e_3) throw e_3.error; }
530
+ }
531
+ return pipelineString;
532
+ }
533
+ /**
534
+ * @private internal util of pipelineJsonToString
535
+ */
536
+ function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
537
+ var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
538
+ var parameterString = "{".concat(name, "}");
539
+ if (description) {
540
+ parameterString = "".concat(parameterString, " ").concat(description);
541
+ }
542
+ return parameterString;
543
+ }
544
+ /**
545
+ * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
546
+ * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
547
+ * TODO: Escape all
548
+ */
549
+
550
+ /**
551
+ * @@@
552
+ */
553
+ function deepClone(objectValue) {
554
+ return JSON.parse(JSON.stringify(objectValue));
555
+ /*
556
+ TODO: [🧠] Is there a better implementation?
557
+ > const propertyNames = Object.getOwnPropertyNames(objectValue);
558
+ > for (const propertyName of propertyNames) {
559
+ > const value = (objectValue as really_any)[propertyName];
560
+ > if (value && typeof value === 'object') {
561
+ > deepClone(value);
562
+ > }
563
+ > }
564
+ > return Object.assign({}, objectValue);
565
+ */
566
+ }
567
+ /**
568
+ * TODO: [🔼] Export from `@promptbook/utils`
569
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
570
+ */
571
+
572
+ /**
573
+ * @@@
574
+ *
575
+ * TODO: [🔼] Export with addUsage
576
+ */
577
+ var ZERO_USAGE = deepFreeze({
578
+ price: { value: 0 },
579
+ input: {
580
+ tokensCount: { value: 0 },
581
+ charactersCount: { value: 0 },
582
+ wordsCount: { value: 0 },
583
+ sentencesCount: { value: 0 },
584
+ linesCount: { value: 0 },
585
+ paragraphsCount: { value: 0 },
586
+ pagesCount: { value: 0 },
587
+ },
588
+ output: {
589
+ tokensCount: { value: 0 },
590
+ charactersCount: { value: 0 },
591
+ wordsCount: { value: 0 },
592
+ sentencesCount: { value: 0 },
593
+ linesCount: { value: 0 },
594
+ paragraphsCount: { value: 0 },
595
+ pagesCount: { value: 0 },
596
+ },
597
+ });
598
+ /**
599
+ * Function `addUsage` will add multiple usages into one
600
+ *
601
+ * Note: If you provide 0 values, it returns ZERO_USAGE
602
+ */
603
+ function addUsage() {
604
+ var usageItems = [];
605
+ for (var _i = 0; _i < arguments.length; _i++) {
606
+ usageItems[_i] = arguments[_i];
607
+ }
608
+ return usageItems.reduce(function (acc, item) {
609
+ var e_1, _a, e_2, _b;
610
+ var _c;
611
+ acc.price.value += ((_c = item.price) === null || _c === void 0 ? void 0 : _c.value) || 0;
612
+ try {
613
+ for (var _d = __values(Object.keys(acc.input)), _e = _d.next(); !_e.done; _e = _d.next()) {
614
+ var key = _e.value;
615
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
616
+ //@ts-ignore
617
+ if (item.input[key]) {
618
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
619
+ //@ts-ignore
620
+ acc.input[key].value += item.input[key].value || 0;
621
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
622
+ //@ts-ignore
623
+ if (item.input[key].isUncertain) {
624
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
625
+ //@ts-ignore
626
+ acc.input[key].isUncertain = true;
627
+ }
628
+ }
629
+ }
630
+ }
631
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
632
+ finally {
633
+ try {
634
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
635
+ }
636
+ finally { if (e_1) throw e_1.error; }
637
+ }
638
+ try {
639
+ for (var _f = __values(Object.keys(acc.output)), _g = _f.next(); !_g.done; _g = _f.next()) {
640
+ var key = _g.value;
641
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
642
+ //@ts-ignore
643
+ if (item.output[key]) {
644
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
645
+ //@ts-ignore
646
+ acc.output[key].value += item.output[key].value || 0;
647
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
648
+ //@ts-ignore
649
+ if (item.output[key].isUncertain) {
650
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
651
+ //@ts-ignore
652
+ acc.output[key].isUncertain = true;
653
+ }
654
+ }
655
+ }
656
+ }
657
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
658
+ finally {
659
+ try {
660
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
661
+ }
662
+ finally { if (e_2) throw e_2.error; }
663
+ }
664
+ return acc;
665
+ }, deepClone(ZERO_USAGE));
726
666
  }
667
+
727
668
  /**
728
- * @private internal util of pipelineJsonToString
669
+ * Async version of Array.forEach
670
+ *
671
+ * @param array - Array to iterate over
672
+ * @param options - Options for the function
673
+ * @param callbackfunction - Function to call for each item
729
674
  */
730
- function promptTemplateParameterJsonToString(promptTemplateParameterJson) {
731
- var name = promptTemplateParameterJson.name, description = promptTemplateParameterJson.description;
732
- var parameterString = "{".concat(name, "}");
733
- if (description) {
734
- parameterString = "".concat(parameterString, " ").concat(description);
735
- }
736
- return parameterString;
675
+ function forEachAsync(array, options, callbackfunction) {
676
+ return __awaiter(this, void 0, void 0, function () {
677
+ var _a, maxParallelCount, index, runningTasks, tasks, _loop_1, _b, _c, item, e_1_1;
678
+ var e_1, _d;
679
+ return __generator(this, function (_e) {
680
+ switch (_e.label) {
681
+ case 0:
682
+ _a = options.maxParallelCount, maxParallelCount = _a === void 0 ? Infinity : _a;
683
+ index = 0;
684
+ runningTasks = [];
685
+ tasks = [];
686
+ _loop_1 = function (item) {
687
+ var currentIndex, task;
688
+ return __generator(this, function (_f) {
689
+ switch (_f.label) {
690
+ case 0:
691
+ currentIndex = index++;
692
+ task = callbackfunction(item, currentIndex, array);
693
+ tasks.push(task);
694
+ runningTasks.push(task);
695
+ /* not await */ Promise.resolve(task).then(function () {
696
+ runningTasks = runningTasks.filter(function (t) { return t !== task; });
697
+ });
698
+ if (!(maxParallelCount < runningTasks.length)) return [3 /*break*/, 2];
699
+ return [4 /*yield*/, Promise.race(runningTasks)];
700
+ case 1:
701
+ _f.sent();
702
+ _f.label = 2;
703
+ case 2: return [2 /*return*/];
704
+ }
705
+ });
706
+ };
707
+ _e.label = 1;
708
+ case 1:
709
+ _e.trys.push([1, 6, 7, 8]);
710
+ _b = __values(array), _c = _b.next();
711
+ _e.label = 2;
712
+ case 2:
713
+ if (!!_c.done) return [3 /*break*/, 5];
714
+ item = _c.value;
715
+ return [5 /*yield**/, _loop_1(item)];
716
+ case 3:
717
+ _e.sent();
718
+ _e.label = 4;
719
+ case 4:
720
+ _c = _b.next();
721
+ return [3 /*break*/, 2];
722
+ case 5: return [3 /*break*/, 8];
723
+ case 6:
724
+ e_1_1 = _e.sent();
725
+ e_1 = { error: e_1_1 };
726
+ return [3 /*break*/, 8];
727
+ case 7:
728
+ try {
729
+ if (_c && !_c.done && (_d = _b.return)) _d.call(_b);
730
+ }
731
+ finally { if (e_1) throw e_1.error; }
732
+ return [7 /*endfinally*/];
733
+ case 8: return [4 /*yield*/, Promise.all(tasks)];
734
+ case 9:
735
+ _e.sent();
736
+ return [2 /*return*/];
737
+ }
738
+ });
739
+ });
737
740
  }
738
- /**
739
- * TODO: !!!! Implement new features and commands into `promptTemplateParameterJsonToString`
740
- * TODO: [🧠] Is there a way to auto-detect missing features in pipelineJsonToString
741
- * TODO: Escape all
742
- */
741
+
742
+ 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"}];
743
743
 
744
744
  /**
745
745
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -1172,79 +1172,100 @@
1172
1172
  }(Error));
1173
1173
 
1174
1174
  /**
1175
- * Library of promptbooks that groups together promptbooks for an application.
1176
- * This implementation is a very thin wrapper around the Array / Map of promptbooks.
1175
+ * Unprepare just strips the preparation data of the pipeline
1176
+ */
1177
+ function unpreparePipeline(pipeline) {
1178
+ var personas = pipeline.personas, knowledgeSources = pipeline.knowledgeSources;
1179
+ personas = personas.map(function (persona) { return (__assign(__assign({}, persona), { modelRequirements: undefined, preparationIds: undefined })); });
1180
+ knowledgeSources = knowledgeSources.map(function (knowledgeSource) { return (__assign(__assign({}, knowledgeSource), { preparationIds: undefined })); });
1181
+ return __assign(__assign({}, pipeline), { knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1182
+ }
1183
+ /**
1184
+ * TODO: [🔼] !!! Export via `@promptbook/core`
1185
+ * TODO: Write tests for `preparePipeline`
1186
+ */
1187
+
1188
+ /**
1189
+ * Library of pipelines that groups together pipelines for an application.
1190
+ * This implementation is a very thin wrapper around the Array / Map of pipelines.
1177
1191
  *
1178
1192
  * @private use `createCollectionFromJson` instead
1179
- * @see https://github.com/webgptorg/promptbook#promptbook-collection
1193
+ * @see https://github.com/webgptorg/pipeline#pipeline-collection
1180
1194
  */
1181
1195
  var SimplePipelineCollection = /** @class */ (function () {
1182
1196
  /**
1183
- * Constructs a pipeline collection from promptbooks
1197
+ * Constructs a pipeline collection from pipelines
1184
1198
  *
1185
- * @param promptbooks @@@
1199
+ * @param pipelines @@@
1186
1200
  *
1187
1201
  * @private Use instead `createCollectionFromJson`
1188
- * Note: During the construction logic of all promptbooks are validated
1202
+ * Note: During the construction logic of all pipelines are validated
1189
1203
  * Note: It is not recommended to use this constructor directly, use `createCollectionFromJson` *(or other variant)* instead
1190
1204
  */
1191
1205
  function SimplePipelineCollection() {
1192
1206
  var e_1, _a;
1193
- var promptbooks = [];
1207
+ var pipelines = [];
1194
1208
  for (var _i = 0; _i < arguments.length; _i++) {
1195
- promptbooks[_i] = arguments[_i];
1209
+ pipelines[_i] = arguments[_i];
1196
1210
  }
1197
1211
  this.collection = new Map();
1198
1212
  try {
1199
- for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
1200
- var promptbook = promptbooks_1_1.value;
1201
- if (promptbook.pipelineUrl === undefined) {
1202
- throw new ReferenceError$1(spaceTrim.spaceTrim("\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 ")));
1213
+ for (var pipelines_1 = __values(pipelines), pipelines_1_1 = pipelines_1.next(); !pipelines_1_1.done; pipelines_1_1 = pipelines_1.next()) {
1214
+ var pipeline = pipelines_1_1.value;
1215
+ // TODO: [👠] DRY
1216
+ if (pipeline.pipelineUrl === undefined) {
1217
+ throw new ReferenceError$1(spaceTrim.spaceTrim("\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 ")));
1203
1218
  }
1204
- validatePipeline(promptbook);
1219
+ // Note: [🐨]
1220
+ validatePipeline(pipeline);
1221
+ // TODO: [🦄] DRY
1205
1222
  // Note: [🦄]
1206
- if (this.collection.has(promptbook.pipelineUrl) &&
1207
- pipelineJsonToString(promptbook) !== pipelineJsonToString(this.collection.get(promptbook.pipelineUrl))) {
1208
- var existing = this.collection.get(promptbook.pipelineUrl);
1209
- throw new ReferenceError$1(spaceTrim.spaceTrim("\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 ")));
1223
+ if (
1224
+ // TODO: [🐽]
1225
+ this.collection.has(pipeline.pipelineUrl) &&
1226
+ pipelineJsonToString(unpreparePipeline(pipeline)) !==
1227
+ pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1228
+ var existing = this.collection.get(pipeline.pipelineUrl);
1229
+ throw new ReferenceError$1(spaceTrim.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 ")));
1210
1230
  }
1211
- this.collection.set(promptbook.pipelineUrl, promptbook);
1231
+ // Note: [🧠] Overwrite existing pipeline with the same URL
1232
+ this.collection.set(pipeline.pipelineUrl, pipeline);
1212
1233
  }
1213
1234
  }
1214
1235
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
1215
1236
  finally {
1216
1237
  try {
1217
- if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
1238
+ if (pipelines_1_1 && !pipelines_1_1.done && (_a = pipelines_1.return)) _a.call(pipelines_1);
1218
1239
  }
1219
1240
  finally { if (e_1) throw e_1.error; }
1220
1241
  }
1221
1242
  }
1222
1243
  /**
1223
- * Gets all promptbooks in the collection
1244
+ * Gets all pipelines in the collection
1224
1245
  */
1225
1246
  SimplePipelineCollection.prototype.listPipelines = function () {
1226
1247
  return Array.from(this.collection.keys());
1227
1248
  };
1228
1249
  /**
1229
- * Gets promptbook by its URL
1250
+ * Gets pipeline by its URL
1230
1251
  *
1231
1252
  * Note: This is not a direct fetching from the URL, but a lookup in the collection
1232
1253
  */
1233
1254
  SimplePipelineCollection.prototype.getPipelineByUrl = function (url) {
1234
1255
  var _this = this;
1235
- var promptbook = this.collection.get(url);
1236
- if (!promptbook) {
1256
+ var pipeline = this.collection.get(url);
1257
+ if (!pipeline) {
1237
1258
  if (this.listPipelines().length === 0) {
1238
- throw new NotFoundError(spaceTrim.spaceTrim("\n Promptbook with url \"".concat(url, "\" not found\n\n No promptbooks available\n ")));
1259
+ throw new NotFoundError(spaceTrim.spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
1239
1260
  }
1240
- throw new NotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPipelines()
1261
+ throw new NotFoundError(spaceTrim.spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
1241
1262
  .map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
1242
1263
  .join('\n')), "\n\n "); }));
1243
1264
  }
1244
- return promptbook;
1265
+ return pipeline;
1245
1266
  };
1246
1267
  /**
1247
- * Checks whether given prompt was defined in any promptbook in the collection
1268
+ * Checks whether given prompt was defined in any pipeline in the collection
1248
1269
  */
1249
1270
  SimplePipelineCollection.prototype.isResponsibleForPrompt = function (prompt) {
1250
1271
  return true;
@@ -1647,39 +1668,6 @@
1647
1668
  * TODO: [🧠] Can this return type be better typed than void
1648
1669
  */
1649
1670
 
1650
- /**
1651
- * Create difference set of two sets.
1652
- *
1653
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
1654
- */
1655
- function difference(a, b, isEqual) {
1656
- var e_1, _a;
1657
- if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
1658
- var diff = new Set();
1659
- var _loop_1 = function (itemA) {
1660
- if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
1661
- diff.add(itemA);
1662
- }
1663
- };
1664
- try {
1665
- for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
1666
- var itemA = _c.value;
1667
- _loop_1(itemA);
1668
- }
1669
- }
1670
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1671
- finally {
1672
- try {
1673
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1674
- }
1675
- finally { if (e_1) throw e_1.error; }
1676
- }
1677
- return diff;
1678
- }
1679
- /**
1680
- * TODO: [🧠][💯] Maybe also implement symmetricDifference
1681
- */
1682
-
1683
1671
  /**
1684
1672
  * Parses the template and returns the list of all parameter names
1685
1673
  *
@@ -1813,46 +1801,6 @@
1813
1801
  * TODO: [🔣] If script require contentLanguage
1814
1802
  */
1815
1803
 
1816
- /**
1817
- * Creates a new set with all elements that are present in either set
1818
- *
1819
- * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
1820
- */
1821
- function union() {
1822
- var e_1, _a, e_2, _b;
1823
- var sets = [];
1824
- for (var _i = 0; _i < arguments.length; _i++) {
1825
- sets[_i] = arguments[_i];
1826
- }
1827
- var union = new Set();
1828
- try {
1829
- for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
1830
- var set = sets_1_1.value;
1831
- try {
1832
- for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
1833
- var item = _d.value;
1834
- union.add(item);
1835
- }
1836
- }
1837
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1838
- finally {
1839
- try {
1840
- if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1841
- }
1842
- finally { if (e_2) throw e_2.error; }
1843
- }
1844
- }
1845
- }
1846
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1847
- finally {
1848
- try {
1849
- if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
1850
- }
1851
- finally { if (e_1) throw e_1.error; }
1852
- }
1853
- return union;
1854
- }
1855
-
1856
1804
  /**
1857
1805
  * This error occurs when some expectation is not met in the execution of the pipeline
1858
1806
  *
@@ -2019,7 +1967,7 @@
2019
1967
  throw new PipelineExecutionError(spaceTrim__default["default"](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 "); }));
2020
1968
  }
2021
1969
  else {
2022
- throw new PipelineExecutionError(spaceTrim__default["default"](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
1970
+ throw new PipelineExecutionError(spaceTrim__default["default"](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
2023
1971
  .map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
2024
1972
  .join('\n')), "\n\n "); }));
2025
1973
  }
@@ -2098,7 +2046,7 @@
2098
2046
  llmExecutionTools[_i] = arguments[_i];
2099
2047
  }
2100
2048
  if (llmExecutionTools.length === 0) {
2101
- var warningMessage = spaceTrim__default["default"]("\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 ");
2049
+ var warningMessage = spaceTrim__default["default"]("\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 ");
2102
2050
  // TODO: [🟥] Detect browser / node and make it colorfull
2103
2051
  console.warn(warningMessage);
2104
2052
  /*
@@ -2258,6 +2206,79 @@
2258
2206
  return replacedTemplate;
2259
2207
  }
2260
2208
 
2209
+ /**
2210
+ * Create difference set of two sets.
2211
+ *
2212
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2213
+ */
2214
+ function difference(a, b, isEqual) {
2215
+ var e_1, _a;
2216
+ if (isEqual === void 0) { isEqual = function (a, b) { return a === b; }; }
2217
+ var diff = new Set();
2218
+ var _loop_1 = function (itemA) {
2219
+ if (!Array.from(b).some(function (itemB) { return isEqual(itemA, itemB); })) {
2220
+ diff.add(itemA);
2221
+ }
2222
+ };
2223
+ try {
2224
+ for (var _b = __values(Array.from(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
2225
+ var itemA = _c.value;
2226
+ _loop_1(itemA);
2227
+ }
2228
+ }
2229
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2230
+ finally {
2231
+ try {
2232
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2233
+ }
2234
+ finally { if (e_1) throw e_1.error; }
2235
+ }
2236
+ return diff;
2237
+ }
2238
+ /**
2239
+ * TODO: [🧠][💯] Maybe also implement symmetricDifference
2240
+ */
2241
+
2242
+ /**
2243
+ * Creates a new set with all elements that are present in either set
2244
+ *
2245
+ * @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
2246
+ */
2247
+ function union() {
2248
+ var e_1, _a, e_2, _b;
2249
+ var sets = [];
2250
+ for (var _i = 0; _i < arguments.length; _i++) {
2251
+ sets[_i] = arguments[_i];
2252
+ }
2253
+ var union = new Set();
2254
+ try {
2255
+ for (var sets_1 = __values(sets), sets_1_1 = sets_1.next(); !sets_1_1.done; sets_1_1 = sets_1.next()) {
2256
+ var set = sets_1_1.value;
2257
+ try {
2258
+ for (var _c = (e_2 = void 0, __values(Array.from(set))), _d = _c.next(); !_d.done; _d = _c.next()) {
2259
+ var item = _d.value;
2260
+ union.add(item);
2261
+ }
2262
+ }
2263
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2264
+ finally {
2265
+ try {
2266
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
2267
+ }
2268
+ finally { if (e_2) throw e_2.error; }
2269
+ }
2270
+ }
2271
+ }
2272
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2273
+ finally {
2274
+ try {
2275
+ if (sets_1_1 && !sets_1_1.done && (_a = sets_1.return)) _a.call(sets_1);
2276
+ }
2277
+ finally { if (e_1) throw e_1.error; }
2278
+ }
2279
+ return union;
2280
+ }
2281
+
2261
2282
  /**
2262
2283
  * Counts number of characters in the text
2263
2284
  */
@@ -2385,7 +2406,7 @@
2385
2406
  pipeline = rawPipeline;
2386
2407
  }
2387
2408
  else {
2388
- console.warn(spaceTrim.spaceTrim("\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 "));
2409
+ console.warn(spaceTrim.spaceTrim("\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 ")));
2389
2410
  }
2390
2411
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2391
2412
  function getContextForTemplate(// <- TODO: [🧠][🥜]
@@ -5463,11 +5484,11 @@
5463
5484
  }
5464
5485
 
5465
5486
  /**
5466
- * Constructs Promptbook from given directory
5487
+ * Constructs Pipeline from given directory
5467
5488
  *
5468
5489
  * Note: Works only in Node.js environment because it reads the file system
5469
5490
  *
5470
- * @param path - path to the directory with promptbooks
5491
+ * @param path - path to the directory with pipelines
5471
5492
  * @param options - Misc options for the collection
5472
5493
  * @returns PipelineCollection
5473
5494
  */
@@ -5497,20 +5518,31 @@
5497
5518
  }
5498
5519
  _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;
5499
5520
  collection = createCollectionFromPromise(function () { return __awaiter(_this, void 0, void 0, function () {
5500
- var fileNames, promptbooks, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
5521
+ var fileNames, collection, _loop_1, fileNames_1, fileNames_1_1, fileName, e_1_1;
5501
5522
  var e_1, _a;
5502
5523
  return __generator(this, function (_b) {
5503
5524
  switch (_b.label) {
5504
5525
  case 0:
5505
5526
  if (isVerbose) {
5506
- console.info("Creating pipeline collection from path ".concat(path$1.split('\\').join('/')));
5527
+ console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path$1.split('\\').join('/'))));
5507
5528
  }
5508
5529
  return [4 /*yield*/, listAllFiles(path$1, isRecursive)];
5509
5530
  case 1:
5510
5531
  fileNames = _b.sent();
5511
- promptbooks = [];
5532
+ // Note: First load all .ptbk.json and then .ptbk.md files
5533
+ // .ptbk.json can be prepared so it is faster to load
5534
+ fileNames.sort(function (a, b) {
5535
+ if (a.endsWith('.ptbk.json') && b.endsWith('.ptbk.md')) {
5536
+ return -1;
5537
+ }
5538
+ if (a.endsWith('.ptbk.md') && b.endsWith('.ptbk.json')) {
5539
+ return 1;
5540
+ }
5541
+ return 0;
5542
+ });
5543
+ collection = new Map();
5512
5544
  _loop_1 = function (fileName) {
5513
- var sourceFile, promptbook, pipelineString, _c, _d, error_1, wrappedErrorMessage;
5545
+ var sourceFile, pipeline, pipelineString, _c, _d, existing, error_1, wrappedErrorMessage;
5514
5546
  return __generator(this, function (_e) {
5515
5547
  switch (_e.label) {
5516
5548
  case 0:
@@ -5518,53 +5550,67 @@
5518
5550
  _e.label = 1;
5519
5551
  case 1:
5520
5552
  _e.trys.push([1, 8, , 9]);
5521
- promptbook = null;
5553
+ pipeline = null;
5522
5554
  if (!fileName.endsWith('.ptbk.md')) return [3 /*break*/, 4];
5523
5555
  return [4 /*yield*/, promises.readFile(fileName, 'utf8')];
5524
5556
  case 2:
5525
5557
  pipelineString = (_e.sent());
5526
5558
  return [4 /*yield*/, pipelineStringToJson(pipelineString, options)];
5527
5559
  case 3:
5528
- promptbook = _e.sent();
5529
- promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
5560
+ pipeline = _e.sent();
5561
+ pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
5530
5562
  return [3 /*break*/, 7];
5531
5563
  case 4:
5532
5564
  if (!fileName.endsWith('.ptbk.json')) return [3 /*break*/, 6];
5533
- if (isVerbose) {
5534
- console.info("Loading ".concat(fileName.split('\\').join('/')));
5535
- }
5536
5565
  _d = (_c = JSON).parse;
5537
5566
  return [4 /*yield*/, promises.readFile(fileName, 'utf8')];
5538
5567
  case 5:
5539
5568
  // TODO: Handle non-valid JSON files
5540
- promptbook = _d.apply(_c, [_e.sent()]);
5569
+ pipeline = _d.apply(_c, [_e.sent()]);
5541
5570
  // TODO: [🌗]
5542
- promptbook = __assign(__assign({}, promptbook), { sourceFile: sourceFile });
5571
+ pipeline = __assign(__assign({}, pipeline), { sourceFile: sourceFile });
5543
5572
  return [3 /*break*/, 7];
5544
5573
  case 6:
5545
5574
  if (isVerbose) {
5546
- console.info("Skipping file ".concat(fileName.split('\\').join('/')));
5575
+ console.info(colors__default["default"].gray("Skipping file ".concat(fileName.split('\\').join('/'))));
5547
5576
  }
5548
5577
  _e.label = 7;
5549
5578
  case 7:
5550
5579
  // ---
5551
- if (promptbook !== null) {
5552
- if (!promptbook.pipelineUrl) {
5580
+ if (pipeline !== null) {
5581
+ // TODO: [👠] DRY
5582
+ if (pipeline.pipelineUrl === undefined) {
5553
5583
  if (isVerbose) {
5554
- console.info("Not loading ".concat(fileName.split('\\').join('/'), " - missing URL"));
5584
+ console.info(colors__default["default"].red("Can not load pipeline from ".concat(fileName
5585
+ .split('\\')
5586
+ .join('/'), " because of missing URL")));
5555
5587
  }
5556
5588
  }
5557
5589
  else {
5558
- if (isVerbose) {
5559
- console.info("Loading ".concat(fileName.split('\\').join('/')));
5590
+ // Note: [🐨] Pipeline is checked multiple times
5591
+ // TODO: Maybe once is enough BUT be sure to check it - better to check it multiple times than not at all
5592
+ validatePipeline(pipeline);
5593
+ if (
5594
+ // TODO: [🐽] comparePipelines(pipeline1,pipeline2): 'IDENTICAL' |'IDENTICAL_UNPREPARED' | 'IDENTICAL_INTERFACE' | 'DIFFERENT'
5595
+ !collection.has(pipeline.pipelineUrl)) {
5596
+ if (isVerbose) {
5597
+ console.info(colors__default["default"].gray("Loaded pipeline ".concat(fileName.split('\\').join('/'), "\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060")));
5598
+ }
5599
+ // Note: [🦄] Pipeline with same url uniqueness will be double-checked automatically in SimplePipelineCollection
5600
+ collection.set(pipeline.pipelineUrl, pipeline);
5560
5601
  }
5561
- if (!isCrashedOnError) {
5562
- // Note: Validate promptbook to check if it is logically correct to not crash on invalid promptbooks
5563
- // But be handled in current try-catch block
5564
- validatePipeline(promptbook);
5602
+ else if (pipelineJsonToString(unpreparePipeline(pipeline)) ===
5603
+ pipelineJsonToString(unpreparePipeline(collection.get(pipeline.pipelineUrl)))) {
5604
+ if (isVerbose) {
5605
+ console.info(colors__default["default"].gray("Skipped pipeline ".concat(fileName
5606
+ .split('\\')
5607
+ .join('/'), " \u2013\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060\u2060 identical pipeline in the collection")));
5608
+ }
5609
+ }
5610
+ else {
5611
+ existing = collection.get(pipeline.pipelineUrl);
5612
+ throw new ReferenceError(spaceTrim__default["default"]("\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 ")));
5565
5613
  }
5566
- // Note: [🦄] Promptbook with same url uniqueness will be checked automatically in SimplePipelineCollection
5567
- promptbooks.push(promptbook);
5568
5614
  }
5569
5615
  }
5570
5616
  return [3 /*break*/, 9];
@@ -5573,7 +5619,7 @@
5573
5619
  if (!(error_1 instanceof Error)) {
5574
5620
  throw error_1;
5575
5621
  }
5576
- wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n Error during loading pipeline from file ".concat(fileName.split('\\').join('/'), ":\n\n ").concat(block(error_1.message), "\n\n "); });
5622
+ wrappedErrorMessage = spaceTrim__default["default"](function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
5577
5623
  if (isCrashedOnError) {
5578
5624
  throw new CollectionError(wrappedErrorMessage);
5579
5625
  }
@@ -5610,7 +5656,7 @@
5610
5656
  }
5611
5657
  finally { if (e_1) throw e_1.error; }
5612
5658
  return [7 /*endfinally*/];
5613
- case 9: return [2 /*return*/, promptbooks];
5659
+ case 9: return [2 /*return*/, Array.from(collection.values())];
5614
5660
  }
5615
5661
  });
5616
5662
  }); });
@@ -5684,8 +5730,8 @@
5684
5730
  });
5685
5731
  }
5686
5732
  /**
5687
- * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json promptbooks
5688
- * Note: [🟢] This code should never be published outside of `@promptbook/node`
5733
+ * TODO: !!!! [🧠] Library precompilation and do not mix markdown and json pipelines
5734
+ * Note: [🟢] This code should never be published outside of `@pipeline/node`
5689
5735
  */
5690
5736
 
5691
5737
  /**