@promptbook/cli 0.81.0-5 → 0.81.0-7

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
@@ -29,15 +29,17 @@ import { Converter } from 'showdown';
29
29
  /**
30
30
  * The version of the Book language
31
31
  *
32
+ * @generated
32
33
  * @see https://github.com/webgptorg/book
33
34
  */
34
35
  var BOOK_LANGUAGE_VERSION = '1.0.0';
35
36
  /**
36
37
  * The version of the Promptbook engine
37
38
  *
39
+ * @generated
38
40
  * @see https://github.com/webgptorg/promptbook
39
41
  */
40
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-4';
42
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-6';
41
43
  /**
42
44
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
43
45
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -235,6 +237,26 @@ var GENERATOR_WARNING_BY_PROMPTBOOK_CLI = "\u26A0\uFE0F WARNING: This code has b
235
237
  * @private within the repository - too low-level in comparison with other `MAX_...`
236
238
  */
237
239
  var LOOP_LIMIT = 1000;
240
+ /**
241
+ * Strings to represent various values in the context of parameter values
242
+ *
243
+ * @public exported from `@promptbook/utils`
244
+ */
245
+ var VALUE_STRINGS = {
246
+ empty: '(nothing; empty string)',
247
+ null: '(no value; null)',
248
+ undefined: '(unknown value; undefined)',
249
+ nan: '(not a number; NaN)',
250
+ infinity: '(infinity; ∞)',
251
+ negativeInfinity: '(negative infinity; -∞)',
252
+ unserializable: '(unserializable value)',
253
+ };
254
+ /**
255
+ * Small number limit
256
+ *
257
+ * @public exported from `@promptbook/utils`
258
+ */
259
+ var SMALL_NUMBER = 0.001;
238
260
  /**
239
261
  * Timeout for the connections in milliseconds
240
262
  *
@@ -353,6 +375,12 @@ var DEFAULT_IS_VERBOSE = false;
353
375
  * @public exported from `@promptbook/core`
354
376
  */
355
377
  var DEFAULT_IS_AUTO_INSTALLED = false;
378
+ /**
379
+ * Function name for generated function via `ptbk make` to get the pipeline collection
380
+ *
381
+ * @public exported from `@promptbook/core`
382
+ */
383
+ var DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME = "getPipelineCollection";
356
384
  /**
357
385
  * @@@
358
386
  *
@@ -760,6 +788,7 @@ function exportJson(options) {
760
788
  * @public exported from `@promptbook/core`
761
789
  */
762
790
  var ORDER_OF_PIPELINE_JSON = [
791
+ // Note: [🍙] In this order will be pipeline serialized
763
792
  'title',
764
793
  'pipelineUrl',
765
794
  'bookVersion',
@@ -771,6 +800,7 @@ var ORDER_OF_PIPELINE_JSON = [
771
800
  'preparations',
772
801
  'knowledgeSources',
773
802
  'knowledgePieces',
803
+ 'sources', // <- TODO: [🧠] Where should the `sources` be
774
804
  ];
775
805
  /**
776
806
  * Nonce which is used for replacing things in strings
@@ -2744,7 +2774,7 @@ function forEachAsync(array, options, callbackfunction) {
2744
2774
  });
2745
2775
  }
2746
2776
 
2747
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sourceFile:"./books/prepare-persona.book.md"}];
2777
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",resultingParameterName:"knowledgePieces",dependentParameterNames:["knowledgeContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Knowledge from Markdown\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.book.md`\n- INPUT PARAMETER `{knowledgeContent}` Markdown document content\n- OUTPUT PARAMETER `{knowledgePieces}` The knowledge JSON object\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}\n```\n\n`-> {knowledgePieces}`\n"}],sourceFile:"./books/prepare-knowledge-from-markdown.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",resultingParameterName:"keywords",dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-keywords.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{keywords}` Keywords separated by comma\n\n## Knowledge\n\n<!-- TODO: [🍆] -FORMAT JSON -->\n\n```markdown\nYou are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}\n```\n\n`-> {keywords}`\n"}],sourceFile:"./books/prepare-knowledge-keywords.book.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.book.md",formfactorName:"GENERIC",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"knowledge",title:"Knowledge",content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",resultingParameterName:"title",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-knowledge-title.book.md`\n- INPUT PARAMETER `{knowledgePieceContent}` The content\n- OUTPUT PARAMETER `{title}` The title of the document\n\n## Knowledge\n\n- EXPECT MIN 1 WORD\n- EXPECT MAX 8 WORDS\n\n```markdown\nYou are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-knowledge-title.book.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.book.md",formfactorName:"GENERIC",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-model-requirements",title:"Make modelRequirements",content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",resultingParameterName:"modelRequirements",format:"JSON",dependentParameterNames:["availableModelNames","personaDescription"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Keywords\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-persona.book.md`\n- INPUT PARAMETER `{availableModelNames}` List of available model names separated by comma (,)\n- INPUT PARAMETER `{personaDescription}` Description of the persona\n- OUTPUT PARAMETER `{modelRequirements}` Specific requirements for the model\n\n## Make modelRequirements\n\n- FORMAT JSON\n\n```markdown\nYou are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Example\n\n\\`\\`\\`json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n\\`\\`\\`\n\n## Instructions\n\n- Your output format is JSON object\n- Write just the JSON object, no other text should be present\n- It contains the following keys:\n - `modelName`: The name of the model to use\n - `systemMessage`: The system message to provide context to the model\n - `temperature`: The sampling temperature to use\n\n### Key `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Key `systemMessage`\n\nThe system message is used to communicate instructions or provide context to the model at the beginning of a conversation. It is displayed in a different format compared to user messages, helping the model understand its role in the conversation. The system message typically guides the model's behavior, sets the tone, or specifies desired output from the model. By utilizing the system message effectively, users can steer the model towards generating more accurate and relevant responses.\n\nFor example:\n\n> You are an experienced AI engineer and helpful assistant.\n\n> You are a friendly and knowledgeable chatbot.\n\n### Key `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}\n```\n\n`-> {modelRequirements}`\n"}],sourceFile:"./books/prepare-persona.book.md"}];
2748
2778
 
2749
2779
  /**
2750
2780
  * Prettify the html code
@@ -4581,9 +4611,87 @@ function arrayableToArray(input) {
4581
4611
  return [input];
4582
4612
  }
4583
4613
 
4614
+ /**
4615
+ * Format either small or big number
4616
+ *
4617
+ * @public exported from `@promptbook/utils`
4618
+ */
4619
+ function numberToString(value) {
4620
+ if (value === 0) {
4621
+ return '0';
4622
+ }
4623
+ else if (Number.isNaN(value)) {
4624
+ return VALUE_STRINGS.nan;
4625
+ }
4626
+ else if (value === Infinity) {
4627
+ return VALUE_STRINGS.infinity;
4628
+ }
4629
+ else if (value === -Infinity) {
4630
+ return VALUE_STRINGS.negativeInfinity;
4631
+ }
4632
+ for (var exponent = 0; exponent < 15; exponent++) {
4633
+ var factor = Math.pow(10, exponent);
4634
+ var valueRounded = Math.round(value * factor) / factor;
4635
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
4636
+ return valueRounded.toFixed(exponent);
4637
+ }
4638
+ }
4639
+ return value.toString();
4640
+ }
4641
+
4642
+ /**
4643
+ * Function `valueToString` will convert the given value to string
4644
+ * This is useful and used in the `templateParameters` function
4645
+ *
4646
+ * Note: This function is not just calling `toString` method
4647
+ * It's more complex and can handle this conversion specifically for LLM models
4648
+ * See `VALUE_STRINGS`
4649
+ *
4650
+ * Note: There are 2 similar functions
4651
+ * - `valueToString` converts value to string for LLM models as human-readable string
4652
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
4653
+ *
4654
+ * @public exported from `@promptbook/utils`
4655
+ */
4656
+ function valueToString(value) {
4657
+ try {
4658
+ if (value === '') {
4659
+ return VALUE_STRINGS.empty;
4660
+ }
4661
+ else if (value === null) {
4662
+ return VALUE_STRINGS.null;
4663
+ }
4664
+ else if (value === undefined) {
4665
+ return VALUE_STRINGS.undefined;
4666
+ }
4667
+ else if (typeof value === 'string') {
4668
+ return value;
4669
+ }
4670
+ else if (typeof value === 'number') {
4671
+ return numberToString(value);
4672
+ }
4673
+ else if (value instanceof Date) {
4674
+ return value.toISOString();
4675
+ }
4676
+ else {
4677
+ return JSON.stringify(value);
4678
+ }
4679
+ }
4680
+ catch (error) {
4681
+ if (!(error instanceof Error)) {
4682
+ throw error;
4683
+ }
4684
+ console.error(error);
4685
+ return VALUE_STRINGS.unserializable;
4686
+ }
4687
+ }
4688
+
4584
4689
  /**
4585
4690
  * Replaces parameters in template with values from parameters object
4586
4691
  *
4692
+ * Note: This function is not places strings into string,
4693
+ * It's more complex and can handle this operation specifically for LLM models
4694
+ *
4587
4695
  * @param template the template with parameters in {curly} braces
4588
4696
  * @param parameters the object with parameters
4589
4697
  * @returns the template with replaced parameters
@@ -4633,7 +4741,7 @@ function templateParameters(template, parameters) {
4633
4741
  if (parameterValue === undefined) {
4634
4742
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4635
4743
  }
4636
- parameterValue = parameterValue.toString();
4744
+ parameterValue = valueToString(parameterValue);
4637
4745
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4638
4746
  parameterValue = parameterValue
4639
4747
  .split('\n')
@@ -9547,6 +9655,14 @@ function precompilePipeline(pipelineString) {
9547
9655
  knowledgePieces: [],
9548
9656
  personas: [],
9549
9657
  preparations: [],
9658
+ sources: [
9659
+ {
9660
+ type: 'BOOK',
9661
+ path: null,
9662
+ // <- TODO: !!!!!! Pass here path of the file
9663
+ content: pipelineString,
9664
+ },
9665
+ ],
9550
9666
  };
9551
9667
  function getPipelineIdentification() {
9552
9668
  // Note: This is a 😐 implementation of [🚞]
@@ -9954,7 +10070,6 @@ function precompilePipeline(pipelineString) {
9954
10070
  $pipelineJson.formfactorName = 'GENERIC';
9955
10071
  }
9956
10072
  // =============================================================
9957
- // TODO: [🍙] Maybe do reorder of `$pipelineJson` here
9958
10073
  return exportJson({
9959
10074
  name: 'pipelineJson',
9960
10075
  message: "Result of `precompilePipeline`",
@@ -11086,11 +11201,9 @@ function createCollectionFromDirectory(path, tools, options) {
11086
11201
  , ".json"));
11087
11202
  return [4 /*yield*/, isFileExisting(makedLibraryFilePath, tools.fs)];
11088
11203
  case 3:
11089
- if (!(_f.sent())) {
11090
- console.info(colors.yellow("Tip: Prebuild your pipeline collection (file with supposed prebuild ".concat(makedLibraryFilePath, " not found) with CLI util \"ptbk make\" to speed up the collection creation.")));
11091
- }
11204
+ if (!(_f.sent())) ;
11092
11205
  else {
11093
- colors.green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
11206
+ colors.green("(In future, not implemented yet) Using your compiled pipeline collection ".concat(makedLibraryFilePath));
11094
11207
  // TODO: !! Implement;
11095
11208
  // TODO: [🌗]
11096
11209
  }
@@ -11110,10 +11223,10 @@ function createCollectionFromDirectory(path, tools, options) {
11110
11223
  // Note: First load all .book.json and then .book.md files
11111
11224
  // .book.json can be prepared so it is faster to load
11112
11225
  fileNames.sort(function (a, b) {
11113
- if (a.endsWith('.book.json') && b.endsWith('.book.md')) {
11226
+ if (a.endsWith('.json') && b.endsWith('.md')) {
11114
11227
  return -1;
11115
11228
  }
11116
- if (a.endsWith('.book.md') && b.endsWith('.book.json')) {
11229
+ if (a.endsWith('.md') && b.endsWith('.json')) {
11117
11230
  return 1;
11118
11231
  }
11119
11232
  return 0;
@@ -11162,7 +11275,7 @@ function createCollectionFromDirectory(path, tools, options) {
11162
11275
  // TODO: [👠] DRY
11163
11276
  if (pipeline.pipelineUrl === undefined) {
11164
11277
  if (isVerbose) {
11165
- console.info(colors.red("Can not load pipeline from ".concat(fileName
11278
+ console.info(colors.yellow("Can not load pipeline from ".concat(fileName
11166
11279
  .split('\\')
11167
11280
  .join('/'), " because of missing URL")));
11168
11281
  }
@@ -11340,16 +11453,21 @@ function initializeMakeCommand(program) {
11340
11453
  makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
11341
11454
  makeCommand.option('-r, --reload', "Call LLM models even if same prompt with result is in the cache", false);
11342
11455
  makeCommand.option('-v, --verbose', "Is output verbose", false);
11343
- makeCommand.option('-o, --out-file <path>', spaceTrim("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME);
11456
+ makeCommand.option('-o, --output <path>', spaceTrim("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME);
11457
+ makeCommand.option('-fn, --function-name <functionName>', spaceTrim("\n Name of the function to get pipeline collection\n\n Note: This can be used only with \"javascript\" or \"typescript\" format\n\n "), DEFAULT_GET_PIPELINE_COLLECTION_FUNCTION_NAME);
11344
11458
  makeCommand.action(function (path, _a) {
11345
- var projectName = _a.projectName, format = _a.format, validation = _a.validation, isCacheReloaded = _a.reload, isVerbose = _a.verbose, outFile = _a.outFile;
11459
+ var projectName = _a.projectName, format = _a.format, functionName = _a.functionName, validation = _a.validation, isCacheReloaded = _a.reload, isVerbose = _a.verbose, output = _a.output;
11346
11460
  return __awaiter(_this, void 0, void 0, function () {
11347
- var formats, validations, prepareAndScrapeOptions, fs, llm, executables, tools, collection, validations_1, validations_1_1, validation_1, _b, _c, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, collectionJsonItems, saveFile;
11348
- var _d, e_2, _e, e_1, _f;
11461
+ var formats, validations, prepareAndScrapeOptions, fs, llm, executables, tools, collection, pipelinesUrls, validations_1, validations_1_1, validation_1, pipelinesUrls_1, pipelinesUrls_1_1, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, collectionJsonItems, saveFile;
11462
+ var _b, e_2, _c, e_1, _d;
11349
11463
  var _this = this;
11350
- return __generator(this, function (_g) {
11351
- switch (_g.label) {
11464
+ return __generator(this, function (_e) {
11465
+ switch (_e.label) {
11352
11466
  case 0:
11467
+ if (!isValidJavascriptName(functionName)) {
11468
+ console.error(colors.red("Function name \"".concat(functionName, "\" is not valid javascript name")));
11469
+ return [2 /*return*/, process.exit(1)];
11470
+ }
11353
11471
  formats = (format || '')
11354
11472
  .split(',')
11355
11473
  .map(function (_) { return _.trim(); })
@@ -11358,7 +11476,7 @@ function initializeMakeCommand(program) {
11358
11476
  .split(',')
11359
11477
  .map(function (_) { return _.trim(); })
11360
11478
  .filter(function (_) { return _ !== ''; });
11361
- if (outFile !== DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME && formats.length !== 1) {
11479
+ if (output !== DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME && formats.length !== 1) {
11362
11480
  console.error(colors.red("You can only use one format if you specify --out-file"));
11363
11481
  return [2 /*return*/, process.exit(1)];
11364
11482
  }
@@ -11370,85 +11488,89 @@ function initializeMakeCommand(program) {
11370
11488
  llm = $provideLlmToolsForCli(prepareAndScrapeOptions);
11371
11489
  return [4 /*yield*/, $provideExecutablesForNode(prepareAndScrapeOptions)];
11372
11490
  case 1:
11373
- executables = _g.sent();
11374
- _d = {
11491
+ executables = _e.sent();
11492
+ _b = {
11375
11493
  llm: llm,
11376
11494
  fs: fs
11377
11495
  };
11378
11496
  return [4 /*yield*/, $provideScrapersForNode({ fs: fs, llm: llm, executables: executables }, prepareAndScrapeOptions)];
11379
11497
  case 2:
11380
- tools = (_d.scrapers = _g.sent(),
11381
- _d.script = [
11498
+ tools = (_b.scrapers = _e.sent(),
11499
+ _b.script = [
11382
11500
  /*new JavascriptExecutionTools(options)*/
11383
11501
  ],
11384
- _d);
11502
+ _b);
11385
11503
  return [4 /*yield*/, createCollectionFromDirectory(path, tools, {
11386
11504
  isVerbose: isVerbose,
11387
11505
  isRecursive: true,
11388
11506
  // <- TODO: [🍖] Add `intermediateFilesStrategy`
11389
11507
  })];
11390
11508
  case 3:
11391
- collection = _g.sent();
11392
- _g.label = 4;
11509
+ collection = _e.sent();
11510
+ return [4 /*yield*/, collection.listPipelines()];
11393
11511
  case 4:
11394
- _g.trys.push([4, 16, 17, 18]);
11395
- validations_1 = __values(validations), validations_1_1 = validations_1.next();
11396
- _g.label = 5;
11512
+ pipelinesUrls = _e.sent();
11513
+ if (pipelinesUrls.length === 0) {
11514
+ console.error(colors.red("No books found in \"".concat(path, "\"")));
11515
+ return [2 /*return*/, process.exit(1)];
11516
+ }
11517
+ _e.label = 5;
11397
11518
  case 5:
11519
+ _e.trys.push([5, 16, 17, 18]);
11520
+ validations_1 = __values(validations), validations_1_1 = validations_1.next();
11521
+ _e.label = 6;
11522
+ case 6:
11398
11523
  if (!!validations_1_1.done) return [3 /*break*/, 15];
11399
11524
  validation_1 = validations_1_1.value;
11400
- _g.label = 6;
11401
- case 6:
11402
- _g.trys.push([6, 12, 13, 14]);
11403
- e_1 = void 0;
11404
- return [4 /*yield*/, collection.listPipelines()];
11525
+ _e.label = 7;
11405
11526
  case 7:
11406
- _b = (__values.apply(void 0, [_g.sent()])), _c = _b.next();
11407
- _g.label = 8;
11527
+ _e.trys.push([7, 12, 13, 14]);
11528
+ pipelinesUrls_1 = (e_1 = void 0, __values(pipelinesUrls)), pipelinesUrls_1_1 = pipelinesUrls_1.next();
11529
+ _e.label = 8;
11408
11530
  case 8:
11409
- if (!!_c.done) return [3 /*break*/, 11];
11410
- pipelineUrl = _c.value;
11531
+ if (!!pipelinesUrls_1_1.done) return [3 /*break*/, 11];
11532
+ pipelineUrl = pipelinesUrls_1_1.value;
11411
11533
  return [4 /*yield*/, collection.getPipelineByUrl(pipelineUrl)];
11412
11534
  case 9:
11413
- pipeline = _g.sent();
11535
+ pipeline = _e.sent();
11414
11536
  if (validation_1 === 'logic') {
11415
11537
  validatePipeline(pipeline);
11416
11538
  if (isVerbose) {
11417
11539
  console.info(colors.cyan("Validated logic of ".concat(pipeline.pipelineUrl)));
11418
11540
  }
11419
11541
  }
11420
- _g.label = 10;
11542
+ _e.label = 10;
11421
11543
  case 10:
11422
- _c = _b.next();
11544
+ pipelinesUrls_1_1 = pipelinesUrls_1.next();
11423
11545
  return [3 /*break*/, 8];
11424
11546
  case 11: return [3 /*break*/, 14];
11425
11547
  case 12:
11426
- e_1_1 = _g.sent();
11548
+ e_1_1 = _e.sent();
11427
11549
  e_1 = { error: e_1_1 };
11428
11550
  return [3 /*break*/, 14];
11429
11551
  case 13:
11430
11552
  try {
11431
- if (_c && !_c.done && (_f = _b.return)) _f.call(_b);
11553
+ if (pipelinesUrls_1_1 && !pipelinesUrls_1_1.done && (_d = pipelinesUrls_1.return)) _d.call(pipelinesUrls_1);
11432
11554
  }
11433
11555
  finally { if (e_1) throw e_1.error; }
11434
11556
  return [7 /*endfinally*/];
11435
11557
  case 14:
11436
11558
  validations_1_1 = validations_1.next();
11437
- return [3 /*break*/, 5];
11559
+ return [3 /*break*/, 6];
11438
11560
  case 15: return [3 /*break*/, 18];
11439
11561
  case 16:
11440
- e_2_1 = _g.sent();
11562
+ e_2_1 = _e.sent();
11441
11563
  e_2 = { error: e_2_1 };
11442
11564
  return [3 /*break*/, 18];
11443
11565
  case 17:
11444
11566
  try {
11445
- if (validations_1_1 && !validations_1_1.done && (_e = validations_1.return)) _e.call(validations_1);
11567
+ if (validations_1_1 && !validations_1_1.done && (_c = validations_1.return)) _c.call(validations_1);
11446
11568
  }
11447
11569
  finally { if (e_2) throw e_2.error; }
11448
11570
  return [7 /*endfinally*/];
11449
11571
  case 18: return [4 /*yield*/, collectionToJson(collection)];
11450
11572
  case 19:
11451
- collectionJson = _g.sent();
11573
+ collectionJson = _e.sent();
11452
11574
  collectionJsonString = stringifyPipelineJson(collectionJson).trim();
11453
11575
  collectionJsonItems = (function () {
11454
11576
  var firstChar = collectionJsonString.charAt(0);
@@ -11466,10 +11588,10 @@ function initializeMakeCommand(program) {
11466
11588
  return __generator(this, function (_a) {
11467
11589
  switch (_a.label) {
11468
11590
  case 0:
11469
- filename = outFile !== DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11470
- ? outFile
11591
+ filename = output !== DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME
11592
+ ? output
11471
11593
  : join(path, "".concat(DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME, ".").concat(extension));
11472
- if (!outFile.endsWith(".".concat(extension))) {
11594
+ if (!output.endsWith(".".concat(extension))) {
11473
11595
  console.warn(colors.yellow("Warning: Extension of output file should be \"".concat(extension, "\"")));
11474
11596
  }
11475
11597
  return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
@@ -11488,22 +11610,22 @@ function initializeMakeCommand(program) {
11488
11610
  formats = formats.filter(function (format) { return format !== 'json'; });
11489
11611
  return [4 /*yield*/, saveFile('json', collectionJsonString)];
11490
11612
  case 20:
11491
- _g.sent();
11492
- _g.label = 21;
11613
+ _e.sent();
11614
+ _e.label = 21;
11493
11615
  case 21:
11494
11616
  if (!(formats.includes('javascript') || formats.includes('js'))) return [3 /*break*/, 23];
11495
11617
  formats = formats.filter(function (format) { return format !== 'javascript' && format !== 'js'; });
11496
- return [4 /*yield*/, saveFile('js', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
11618
+ return [4 /*yield*/, saveFile('js', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @private internal cache for `").concat(functionName, "`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function ").concat(functionName, "(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
11497
11619
  case 22:
11498
- (_g.sent()) + '\n';
11499
- _g.label = 23;
11620
+ (_e.sent()) + '\n';
11621
+ _e.label = 23;
11500
11622
  case 23:
11501
11623
  if (!(formats.includes('typescript') || formats.includes('ts'))) return [3 /*break*/, 25];
11502
11624
  formats = formats.filter(function (format) { return format !== 'typescript' && format !== 'ts'; });
11503
- return [4 /*yield*/, saveFile('ts', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(): PipelineCollection{\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
11625
+ return [4 /*yield*/, saveFile('ts', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `").concat(functionName, "`\n * @generated\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @generated\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function ").concat(functionName, "(): PipelineCollection{\n if(pipelineCollection===null){\n\n // TODO: !!!!!! Use book string literal notation\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n pipelineCollection = (createCollectionFromJson as (..._: any) => PipelineCollection)(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
11504
11626
  case 24:
11505
- _g.sent();
11506
- _g.label = 25;
11627
+ _e.sent();
11628
+ _e.label = 25;
11507
11629
  case 25:
11508
11630
  if (formats.length > 0) {
11509
11631
  console.warn(colors.yellow("Format ".concat(formats.join(' and '), " is not supported")));
@@ -11753,26 +11875,6 @@ function initializePrettifyCommand(program) {
11753
11875
  * TODO: [🖇] What about symlinks? Maybe flag --follow-symlinks
11754
11876
  */
11755
11877
 
11756
- /**
11757
- * Format either small or big number
11758
- *
11759
- * @private within the repository
11760
- */
11761
- function formatNumber(value) {
11762
- if (value === 0) {
11763
- return '0';
11764
- }
11765
- for (var exponent = 0; exponent < 15; exponent++) {
11766
- var factor = Math.pow(10, exponent);
11767
- var valueRounded = Math.round(value * factor) / factor;
11768
- if (Math.abs(value - valueRounded) / value <
11769
- 0.001 /* <- TODO: Pass as option, pass to executionReportJsonToString as option */) {
11770
- return valueRounded.toFixed(exponent);
11771
- }
11772
- }
11773
- return value.toString();
11774
- }
11775
-
11776
11878
  /**
11777
11879
  * Create a markdown table from a 2D array of strings
11778
11880
  *
@@ -11832,7 +11934,7 @@ function createMarkdownChart(options) {
11832
11934
  }
11833
11935
  finally { if (e_1) throw e_1.error; }
11834
11936
  }
11835
- var legend = "_Note: Each \u2588 represents ".concat(formatNumber(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(formatNumber(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
11937
+ var legend = "_Note: Each \u2588 represents ".concat(numberToString(1 / scale), " ").concat(unitName, ", width of ").concat(valueHeader.toLowerCase(), " is ").concat(numberToString(to - from), " ").concat(unitName, " = ").concat(width, " squares_");
11836
11938
  return createMarkdownTable(table) + '\n\n' + legend;
11837
11939
  }
11838
11940
  /**
@@ -11961,7 +12063,7 @@ function executionReportJsonToString(executionReportJson, options) {
11961
12063
  headerList.push("COMPLETED AT ".concat(moment(completedAt).format("YYYY-MM-DD HH:mm:ss")));
11962
12064
  headerList.push("TOTAL DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
11963
12065
  headerList.push("TOTAL LLM DURATION ".concat(llmDuration.humanize(MOMENT_ARG_THRESHOLDS)));
11964
- headerList.push("TOTAL COST $".concat(formatNumber(cost * (1 + taxRate))) +
12066
+ headerList.push("TOTAL COST $".concat(numberToString(cost * (1 + taxRate))) +
11965
12067
  (executionsWithKnownCost.length === executionReportJson.promptExecutions.length
11966
12068
  ? ''
11967
12069
  : " *(Some cost is unknown)*") +
@@ -12019,7 +12121,7 @@ function executionReportJsonToString(executionReportJson, options) {
12019
12121
  // > taskList.push(`STARTED AT ${moment(startedAt).calendar()}`);
12020
12122
  taskList.push("DURATION ".concat(duration.humanize(MOMENT_ARG_THRESHOLDS)));
12021
12123
  if (typeof ((_g = (_f = promptExecution.result) === null || _f === void 0 ? void 0 : _f.usage) === null || _g === void 0 ? void 0 : _g.price) === 'number') {
12022
- taskList.push("COST $".concat(formatNumber(promptExecution.result.usage.price * (1 + taxRate))) +
12124
+ taskList.push("COST $".concat(numberToString(promptExecution.result.usage.price * (1 + taxRate))) +
12023
12125
  (taxRate !== 0 ? " *(with tax ".concat(taxRate * 100, "%)*") : ''));
12024
12126
  }
12025
12127
  else {
@@ -14323,6 +14425,10 @@ var _GoogleMetadataRegistration = $llmToolsMetadataRegister.register({
14323
14425
  * For example:
14324
14426
  * - `Date` objects will be converted to string
14325
14427
  *
14428
+ * Note: There are 2 similar functions
14429
+ * - `valueToString` converts value to string for LLM models as human-readable string
14430
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
14431
+ *
14326
14432
  * @private Internal helper function
14327
14433
  */
14328
14434
  function asSerializable(value) {