@promptbook/core 0.67.4 → 0.67.5

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
@@ -9,7 +9,7 @@ import moment from 'moment';
9
9
  /**
10
10
  * The version of the Promptbook library
11
11
  */
12
- var PROMPTBOOK_VERSION = '0.67.3';
12
+ var PROMPTBOOK_VERSION = '0.67.4';
13
13
  // TODO: !!!! List here all the versions and annotate + put into script
14
14
 
15
15
  /*! *****************************************************************************
@@ -1779,7 +1779,7 @@ function forEachAsync(array, options, callbackfunction) {
1779
1779
  });
1780
1780
  }
1781
1781
 
1782
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.3",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},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}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.67.3",parameters:[{name:"knowledgePieceContent",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"},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}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.67.3",parameters:[{name:"knowledgePieceContent",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"},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}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.67.3",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"},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- 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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1782
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.67.4",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT"},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}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.67.4",parameters:[{name:"knowledgePieceContent",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"},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}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.67.4",parameters:[{name:"knowledgePieceContent",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"},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}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.67.4",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"},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- 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}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
1783
1783
 
1784
1784
  var defaultDiacriticsRemovalMap = [
1785
1785
  {
@@ -2748,6 +2748,122 @@ function joinLlmExecutionTools() {
2748
2748
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
2749
2749
  */
2750
2750
 
2751
+ /**
2752
+ * Extracts all code blocks from markdown.
2753
+ *
2754
+ * Note: There are multiple simmilar function:
2755
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
2756
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
2757
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2758
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2759
+ *
2760
+ * @param markdown any valid markdown
2761
+ * @returns code blocks with language and content
2762
+ * @throws {ParsingError} if block is not closed properly
2763
+ * @public exported from `@promptbook/markdown-utils`
2764
+ */
2765
+ function extractAllBlocksFromMarkdown(markdown) {
2766
+ var e_1, _a;
2767
+ var codeBlocks = [];
2768
+ var lines = markdown.split('\n');
2769
+ // Note: [0] Ensure that the last block notated by gt > will be closed
2770
+ lines.push('');
2771
+ var currentCodeBlock = null;
2772
+ try {
2773
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
2774
+ var line = lines_1_1.value;
2775
+ if (line.startsWith('> ') || line === '>') {
2776
+ if (currentCodeBlock === null) {
2777
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
2778
+ } /* not else */
2779
+ if (currentCodeBlock.blockNotation === '>') {
2780
+ if (currentCodeBlock.content !== '') {
2781
+ currentCodeBlock.content += '\n';
2782
+ }
2783
+ currentCodeBlock.content += line.slice(2);
2784
+ }
2785
+ }
2786
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
2787
+ codeBlocks.push(currentCodeBlock);
2788
+ currentCodeBlock = null;
2789
+ }
2790
+ /* not else */
2791
+ if (line.startsWith('```')) {
2792
+ var language = line.slice(3).trim() || null;
2793
+ if (currentCodeBlock === null) {
2794
+ currentCodeBlock = { blockNotation: '```', language: language, content: '' };
2795
+ }
2796
+ else {
2797
+ if (language !== null) {
2798
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
2799
+ }
2800
+ codeBlocks.push(currentCodeBlock);
2801
+ currentCodeBlock = null;
2802
+ }
2803
+ }
2804
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
2805
+ if (currentCodeBlock.content !== '') {
2806
+ currentCodeBlock.content += '\n';
2807
+ }
2808
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
2809
+ }
2810
+ }
2811
+ }
2812
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2813
+ finally {
2814
+ try {
2815
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
2816
+ }
2817
+ finally { if (e_1) throw e_1.error; }
2818
+ }
2819
+ if (currentCodeBlock !== null) {
2820
+ throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
2821
+ }
2822
+ return codeBlocks;
2823
+ }
2824
+ /**
2825
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
2826
+ */
2827
+
2828
+ /**
2829
+ * Extracts extracts exactly one valid JSON code block
2830
+ *
2831
+ * - When given string is a valid JSON as it is, it just returns it
2832
+ * - When there is no JSON code block the function throws a `ParsingError`
2833
+ * - When there are multiple JSON code blocks the function throws a `ParsingError`
2834
+ *
2835
+ * Note: It is not important if marked as ```json BUT if it is VALID JSON
2836
+ * Note: There are multiple simmilar function:
2837
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
2838
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
2839
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2840
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2841
+ *
2842
+ * @public exported from `@promptbook/markdown-utils`
2843
+ * @throws {ParsingError} if there is no valid JSON block in the markdown
2844
+ */
2845
+ function extractJsonBlock(markdown) {
2846
+ if (isValidJsonString(markdown)) {
2847
+ return markdown;
2848
+ }
2849
+ var codeBlocks = extractAllBlocksFromMarkdown(markdown);
2850
+ var jsonBlocks = codeBlocks.filter(function (_a) {
2851
+ var content = _a.content;
2852
+ return isValidJsonString(content);
2853
+ });
2854
+ if (jsonBlocks.length === 0) {
2855
+ throw new Error('There is no valid JSON block in the markdown');
2856
+ }
2857
+ if (jsonBlocks.length > 1) {
2858
+ throw new Error('There are multiple JSON code blocks in the markdown');
2859
+ }
2860
+ return jsonBlocks[0].content;
2861
+ }
2862
+ /**
2863
+ * TODO: Add some auto-healing logic + extract YAML, JSON5, TOML, etc.
2864
+ * TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
2865
+ */
2866
+
2751
2867
  /**
2752
2868
  * Determine if the pipeline is fully prepared
2753
2869
  *
@@ -2799,6 +2915,27 @@ function arrayableToArray(input) {
2799
2915
  return [input];
2800
2916
  }
2801
2917
 
2918
+ /**
2919
+ * Just says that the variable is not used but should be kept
2920
+ * No side effects.
2921
+ *
2922
+ * Note: It can be usefull for:
2923
+ *
2924
+ * 1) Suppressing eager optimization of unused imports
2925
+ * 2) Suppressing eslint errors of unused variables in the tests
2926
+ * 3) Keeping the type of the variable for type testing
2927
+ *
2928
+ * @param value any values
2929
+ * @returns void
2930
+ * @private within the repository
2931
+ */
2932
+ function keepUnused() {
2933
+ var valuesToKeep = [];
2934
+ for (var _i = 0; _i < arguments.length; _i++) {
2935
+ valuesToKeep[_i] = arguments[_i];
2936
+ }
2937
+ }
2938
+
2802
2939
  /**
2803
2940
  * Just marks a place of place where should be something implemented
2804
2941
  * No side effects.
@@ -3261,7 +3398,11 @@ function createPipelineExecutor(options) {
3261
3398
  usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
3262
3399
  dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
3263
3400
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
3264
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n "); }));
3401
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Dependent parameters are not consistent with used parameters:\n\n ".concat(block(pipelineIdentification), "\n\n Dependent parameters:\n ").concat(Array.from(dependentParameterNames)
3402
+ .map(function (name) { return "{".concat(name, "}"); })
3403
+ .join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames)
3404
+ .map(function (name) { return "{".concat(name, "}"); })
3405
+ .join(', '), "\n\n "); }));
3265
3406
  }
3266
3407
  _b = (_a = Object).freeze;
3267
3408
  _c = [{}];
@@ -3556,10 +3697,20 @@ function createPipelineExecutor(options) {
3556
3697
  if (currentTemplate.expectFormat) {
3557
3698
  if (currentTemplate.expectFormat === 'JSON') {
3558
3699
  if (!isValidJsonString(resultString || '')) {
3559
- throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3560
- /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3700
+ // TODO: [🏢] Do more universally via `FormatDefinition`
3701
+ try {
3702
+ resultString = extractJsonBlock(resultString || '');
3703
+ }
3704
+ catch (error) {
3705
+ keepUnused(error);
3706
+ throw new ExpectError(spaceTrim$1(function (block) { return "\n Expected valid JSON string\n\n ".concat(block(
3707
+ /*<- Note: No need for `pipelineIdentification`, it will be catched and added later */ ''), "\n "); }));
3708
+ }
3561
3709
  }
3562
3710
  }
3711
+ else {
3712
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Unknown expectFormat \"".concat(currentTemplate.expectFormat, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
3713
+ }
3563
3714
  }
3564
3715
  // TODO: [💝] Unite object for expecting amount and format
3565
3716
  if (currentTemplate.expectations) {
@@ -3590,7 +3741,18 @@ function createPipelineExecutor(options) {
3590
3741
  return [7 /*endfinally*/];
3591
3742
  case 46:
3592
3743
  if (expectError !== null && attempt === maxAttempts - 1) {
3593
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block(prompt.content), "\n\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(block(resultString || 'null'), "\n ---\n "); }));
3744
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ").concat(block(pipelineIdentification), "\n\n ---\n The Prompt:\n ").concat(block(prompt.content
3745
+ .split('\n')
3746
+ .map(function (line) { return "> ".concat(line); })
3747
+ .join('\n')), "\n\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block(((expectError === null || expectError === void 0 ? void 0 : expectError.message) || '')
3748
+ .split('\n')
3749
+ .map(function (line) { return "> ".concat(line); })
3750
+ .join('\n')), "\n\n Last result:\n ").concat(block(resultString === null
3751
+ ? 'null'
3752
+ : resultString
3753
+ .split('\n')
3754
+ .map(function (line) { return "> ".concat(line); })
3755
+ .join('\n')), "\n ---\n "); }));
3594
3756
  }
3595
3757
  return [2 /*return*/];
3596
3758
  }
@@ -5684,94 +5846,21 @@ function extractAllListItemsFromMarkdown(markdown) {
5684
5846
  return listItems;
5685
5847
  }
5686
5848
 
5687
- /**
5688
- * Extracts all code blocks from markdown.
5689
- *
5690
- * Note: There are 3 simmilar function:
5691
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
5692
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
5693
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
5694
- *
5695
- * @param markdown any valid markdown
5696
- * @returns code blocks with language and content
5697
- * @public exported from `@promptbook/markdown-utils`
5698
- */
5699
- function extractAllBlocksFromMarkdown(markdown) {
5700
- var e_1, _a;
5701
- var codeBlocks = [];
5702
- var lines = markdown.split('\n');
5703
- // Note: [0] Ensure that the last block notated by gt > will be closed
5704
- lines.push('');
5705
- var currentCodeBlock = null;
5706
- try {
5707
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
5708
- var line = lines_1_1.value;
5709
- if (line.startsWith('> ') || line === '>') {
5710
- if (currentCodeBlock === null) {
5711
- currentCodeBlock = { blockNotation: '>', language: null, content: '' };
5712
- } /* not else */
5713
- if (currentCodeBlock.blockNotation === '>') {
5714
- if (currentCodeBlock.content !== '') {
5715
- currentCodeBlock.content += '\n';
5716
- }
5717
- currentCodeBlock.content += line.slice(2);
5718
- }
5719
- }
5720
- else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
5721
- codeBlocks.push(currentCodeBlock);
5722
- currentCodeBlock = null;
5723
- }
5724
- /* not else */
5725
- if (line.startsWith('```')) {
5726
- var language = line.slice(3).trim() || null;
5727
- if (currentCodeBlock === null) {
5728
- currentCodeBlock = { blockNotation: '```', language: language, content: '' };
5729
- }
5730
- else {
5731
- if (language !== null) {
5732
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
5733
- }
5734
- codeBlocks.push(currentCodeBlock);
5735
- currentCodeBlock = null;
5736
- }
5737
- }
5738
- else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
5739
- if (currentCodeBlock.content !== '') {
5740
- currentCodeBlock.content += '\n';
5741
- }
5742
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
5743
- }
5744
- }
5745
- }
5746
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
5747
- finally {
5748
- try {
5749
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
5750
- }
5751
- finally { if (e_1) throw e_1.error; }
5752
- }
5753
- if (currentCodeBlock !== null) {
5754
- throw new ParsingError("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
5755
- }
5756
- return codeBlocks;
5757
- }
5758
- /**
5759
- * TODO: Maybe name for `blockNotation` instead of '```' and '>'
5760
- */
5761
-
5762
5849
  /**
5763
5850
  * Extracts exactly ONE code block from markdown.
5764
5851
  *
5765
- * Note: If there are multiple or no code blocks the function throws an error
5852
+ * - When there are multiple or no code blocks the function throws a `ParsingError`
5766
5853
  *
5767
- * Note: There are 3 simmilar function:
5854
+ * Note: There are multiple simmilar function:
5768
5855
  * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
5856
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
5769
5857
  * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
5770
5858
  * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
5771
5859
  *
5772
5860
  * @param markdown any valid markdown
5773
5861
  * @returns code block with language and content
5774
5862
  * @public exported from `@promptbook/markdown-utils`
5863
+ * @throws {ParsingError} if there is not exactly one code block in the markdown
5775
5864
  */
5776
5865
  function extractOneBlockFromMarkdown(markdown) {
5777
5866
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
@@ -6401,7 +6490,7 @@ function addAutoGeneratedSection(content, options) {
6401
6490
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
6402
6491
  if (!placeForSection) {
6403
6492
  throw new ParsingError(
6404
- // <- [🧠] Maybe something better than `ParsingError`
6493
+ // <- [🧠] Maybe something better tha `ParsingError`
6405
6494
  "No place where to put the section <!--".concat(sectionName, "-->"));
6406
6495
  // <- [🚞]
6407
6496
  }