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