@promptbook/node 0.80.0 → 0.81.0-6

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.
Files changed (39) hide show
  1. package/README.md +6 -0
  2. package/esm/index.es.js +154 -24
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/books/index.d.ts +15 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -6
  6. package/esm/typings/src/_packages/editable.index.d.ts +10 -0
  7. package/esm/typings/src/_packages/templates.index.d.ts +4 -0
  8. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  9. package/esm/typings/src/_packages/utils.index.d.ts +10 -2
  10. package/esm/typings/src/config.d.ts +26 -0
  11. package/esm/typings/src/execution/ExecutionTools.d.ts +7 -0
  12. package/esm/typings/src/execution/PromptbookFetch.d.ts +5 -0
  13. package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
  14. package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +2 -1
  15. package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +2 -1
  16. package/esm/typings/src/high-level-abstractions/index.d.ts +10 -0
  17. package/esm/typings/src/other/templates/getBookTemplate.d.ts +12 -0
  18. package/esm/typings/src/other/templates/getTemplatesPipelineCollection.d.ts +10 -0
  19. package/esm/typings/src/pipeline/PipelineJson/PipelineJson.d.ts +10 -0
  20. package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
  21. package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +7 -0
  22. package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +27 -0
  23. package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.d.ts +3 -3
  24. package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.d.ts +3 -3
  25. package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.d.ts +2 -2
  26. package/esm/typings/src/utils/parameters/numberToString.d.ts +7 -0
  27. package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +6 -2
  28. package/esm/typings/src/utils/parameters/valueToString.d.ts +17 -0
  29. package/esm/typings/src/utils/parameters/valueToString.test.d.ts +1 -0
  30. package/esm/typings/src/utils/serialization/asSerializable.d.ts +4 -0
  31. package/package.json +2 -2
  32. package/umd/index.umd.js +154 -24
  33. package/umd/index.umd.js.map +1 -1
  34. package/esm/typings/src/utils/formatNumber.d.ts +0 -6
  35. /package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.test.d.ts +0 -0
  36. /package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.test.d.ts +0 -0
  37. /package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.test.d.ts +0 -0
  38. /package/esm/typings/src/utils/{formatNumber.test.d.ts → parameters/numberToString.test.d.ts} +0 -0
  39. /package/esm/typings/src/utils/parameters/{replaceParameters.test.d.ts → templateParameters.test.d.ts} +0 -0
package/umd/index.umd.js CHANGED
@@ -43,7 +43,7 @@
43
43
  *
44
44
  * @see https://github.com/webgptorg/promptbook
45
45
  */
46
- var PROMPTBOOK_ENGINE_VERSION = '0.80.0-1';
46
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-5';
47
47
  /**
48
48
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
49
49
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -221,6 +221,26 @@
221
221
  * @private within the repository - too low-level in comparison with other `MAX_...`
222
222
  */
223
223
  var LOOP_LIMIT = 1000;
224
+ /**
225
+ * Strings to represent various values in the context of parameter values
226
+ *
227
+ * @public exported from `@promptbook/utils`
228
+ */
229
+ var VALUE_STRINGS = {
230
+ empty: '(nothing; empty string)',
231
+ null: '(no value; null)',
232
+ undefined: '(unknown value; undefined)',
233
+ nan: '(not a number; NaN)',
234
+ infinity: '(infinity; ∞)',
235
+ negativeInfinity: '(negative infinity; -∞)',
236
+ unserializable: '(unserializable value)',
237
+ };
238
+ /**
239
+ * Small number limit
240
+ *
241
+ * @public exported from `@promptbook/utils`
242
+ */
243
+ var SMALL_NUMBER = 0.001;
224
244
  /**
225
245
  * Short time interval to prevent race conditions in milliseconds
226
246
  *
@@ -576,6 +596,7 @@
576
596
  * @public exported from `@promptbook/core`
577
597
  */
578
598
  var ORDER_OF_PIPELINE_JSON = [
599
+ // Note: [🍙] In this order will be pipeline serialized
579
600
  'title',
580
601
  'pipelineUrl',
581
602
  'bookVersion',
@@ -587,6 +608,7 @@
587
608
  'preparations',
588
609
  'knowledgeSources',
589
610
  'knowledgePieces',
611
+ 'sources', // <- TODO: [🧠] Where should the `sources` be
590
612
  ];
591
613
  /**
592
614
  * Nonce which is used for replacing things in strings
@@ -1245,7 +1267,7 @@
1245
1267
  * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
1246
1268
  */
1247
1269
 
1248
- 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"}];
1270
+ 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"}];
1249
1271
 
1250
1272
  /**
1251
1273
  * Prettify the html code
@@ -3143,16 +3165,94 @@
3143
3165
  return [input];
3144
3166
  }
3145
3167
 
3168
+ /**
3169
+ * Format either small or big number
3170
+ *
3171
+ * @public exported from `@promptbook/utils`
3172
+ */
3173
+ function numberToString(value) {
3174
+ if (value === 0) {
3175
+ return '0';
3176
+ }
3177
+ else if (Number.isNaN(value)) {
3178
+ return VALUE_STRINGS.nan;
3179
+ }
3180
+ else if (value === Infinity) {
3181
+ return VALUE_STRINGS.infinity;
3182
+ }
3183
+ else if (value === -Infinity) {
3184
+ return VALUE_STRINGS.negativeInfinity;
3185
+ }
3186
+ for (var exponent = 0; exponent < 15; exponent++) {
3187
+ var factor = Math.pow(10, exponent);
3188
+ var valueRounded = Math.round(value * factor) / factor;
3189
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
3190
+ return valueRounded.toFixed(exponent);
3191
+ }
3192
+ }
3193
+ return value.toString();
3194
+ }
3195
+
3196
+ /**
3197
+ * Function `valueToString` will convert the given value to string
3198
+ * This is useful and used in the `templateParameters` function
3199
+ *
3200
+ * Note: This function is not just calling `toString` method
3201
+ * It's more complex and can handle this conversion specifically for LLM models
3202
+ * See `VALUE_STRINGS`
3203
+ *
3204
+ * Note: There are 2 similar functions
3205
+ * - `valueToString` converts value to string for LLM models as human-readable string
3206
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
3207
+ *
3208
+ * @public exported from `@promptbook/utils`
3209
+ */
3210
+ function valueToString(value) {
3211
+ try {
3212
+ if (value === '') {
3213
+ return VALUE_STRINGS.empty;
3214
+ }
3215
+ else if (value === null) {
3216
+ return VALUE_STRINGS.null;
3217
+ }
3218
+ else if (value === undefined) {
3219
+ return VALUE_STRINGS.undefined;
3220
+ }
3221
+ else if (typeof value === 'string') {
3222
+ return value;
3223
+ }
3224
+ else if (typeof value === 'number') {
3225
+ return numberToString(value);
3226
+ }
3227
+ else if (value instanceof Date) {
3228
+ return value.toISOString();
3229
+ }
3230
+ else {
3231
+ return JSON.stringify(value);
3232
+ }
3233
+ }
3234
+ catch (error) {
3235
+ if (!(error instanceof Error)) {
3236
+ throw error;
3237
+ }
3238
+ console.error(error);
3239
+ return VALUE_STRINGS.unserializable;
3240
+ }
3241
+ }
3242
+
3146
3243
  /**
3147
3244
  * Replaces parameters in template with values from parameters object
3148
3245
  *
3246
+ * Note: This function is not places strings into string,
3247
+ * It's more complex and can handle this operation specifically for LLM models
3248
+ *
3149
3249
  * @param template the template with parameters in {curly} braces
3150
3250
  * @param parameters the object with parameters
3151
3251
  * @returns the template with replaced parameters
3152
3252
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
3153
3253
  * @public exported from `@promptbook/utils`
3154
3254
  */
3155
- function replaceParameters(template, parameters) {
3255
+ function templateParameters(template, parameters) {
3156
3256
  var e_1, _a;
3157
3257
  try {
3158
3258
  for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -3178,7 +3278,7 @@
3178
3278
  var loopLimit = LOOP_LIMIT;
3179
3279
  var _loop_1 = function () {
3180
3280
  if (loopLimit-- < 0) {
3181
- throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
3281
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
3182
3282
  }
3183
3283
  var precol = match.groups.precol;
3184
3284
  var parameterName = match.groups.parameterName;
@@ -3195,7 +3295,7 @@
3195
3295
  if (parameterValue === undefined) {
3196
3296
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
3197
3297
  }
3198
- parameterValue = parameterValue.toString();
3298
+ parameterValue = valueToString(parameterValue);
3199
3299
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
3200
3300
  parameterValue = parameterValue
3201
3301
  .split('\n')
@@ -3691,7 +3791,7 @@
3691
3791
  }
3692
3792
  return [3 /*break*/, 24];
3693
3793
  case 2:
3694
- $ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
3794
+ $ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
3695
3795
  return [3 /*break*/, 25];
3696
3796
  case 3:
3697
3797
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
@@ -3814,8 +3914,8 @@
3814
3914
  _j = $ongoingTaskResult;
3815
3915
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3816
3916
  promptTitle: task.title,
3817
- promptMessage: replaceParameters(task.description || '', parameters),
3818
- defaultValue: replaceParameters(preparedContent, parameters),
3917
+ promptMessage: templateParameters(task.description || '', parameters),
3918
+ defaultValue: templateParameters(preparedContent, parameters),
3819
3919
  // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
3820
3920
  placeholder: undefined,
3821
3921
  priority: priority,
@@ -3939,7 +4039,7 @@
3939
4039
  if (!isJokerAttempt &&
3940
4040
  task.taskType === 'PROMPT_TASK' &&
3941
4041
  $ongoingTaskResult.$prompt
3942
- // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
4042
+ // <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
3943
4043
  // In that case we don’t want to make a report about it because it’s not a llm execution error
3944
4044
  ) {
3945
4045
  // TODO: [🧠] Maybe put other taskTypes into report
@@ -5266,6 +5366,30 @@
5266
5366
  return false;
5267
5367
  }
5268
5368
 
5369
+ /**
5370
+ * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
5371
+ *
5372
+ * @private as default `fetch` function used in Promptbook scrapers
5373
+ */
5374
+ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
5375
+ var error_1;
5376
+ return __generator(this, function (_a) {
5377
+ switch (_a.label) {
5378
+ case 0:
5379
+ _a.trys.push([0, 2, , 3]);
5380
+ return [4 /*yield*/, fetch(url, init)];
5381
+ case 1: return [2 /*return*/, _a.sent()];
5382
+ case 2:
5383
+ error_1 = _a.sent();
5384
+ if (!(error_1 instanceof Error)) {
5385
+ throw error_1;
5386
+ }
5387
+ throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Can not fetch \"".concat(url, "\"\n\n Fetch error:\n ").concat(block(error_1.message), "\n\n "); }));
5388
+ case 3: return [2 /*return*/];
5389
+ }
5390
+ });
5391
+ }); };
5392
+
5269
5393
  /**
5270
5394
  * @@@
5271
5395
  *
@@ -5274,13 +5398,14 @@
5274
5398
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5275
5399
  var _a;
5276
5400
  return __awaiter(this, void 0, void 0, function () {
5277
- var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5278
- return __generator(this, function (_e) {
5279
- switch (_e.label) {
5401
+ var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
5402
+ return __generator(this, function (_f) {
5403
+ switch (_f.label) {
5280
5404
  case 0:
5405
+ _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
5281
5406
  sourceContent = knowledgeSource.sourceContent;
5282
5407
  name = knowledgeSource.name;
5283
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
5408
+ _c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
5284
5409
  if (!name) {
5285
5410
  name = sourceContentToName(sourceContent);
5286
5411
  }
@@ -5288,7 +5413,7 @@
5288
5413
  url = sourceContent;
5289
5414
  return [4 /*yield*/, fetch(url)];
5290
5415
  case 1:
5291
- response_1 = _e.sent();
5416
+ response_1 = _f.sent();
5292
5417
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
5293
5418
  return [2 /*return*/, {
5294
5419
  source: name,
@@ -5345,7 +5470,7 @@
5345
5470
  mimeType = extensionToMimeType(fileExtension || '');
5346
5471
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
5347
5472
  case 3:
5348
- if (!(_e.sent())) {
5473
+ if (!(_f.sent())) {
5349
5474
  throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
5350
5475
  }
5351
5476
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -8648,6 +8773,14 @@
8648
8773
  knowledgePieces: [],
8649
8774
  personas: [],
8650
8775
  preparations: [],
8776
+ sources: [
8777
+ {
8778
+ type: 'BOOK',
8779
+ path: null,
8780
+ // <- TODO: !!!!!! Pass here path of the file
8781
+ content: pipelineString,
8782
+ },
8783
+ ],
8651
8784
  };
8652
8785
  function getPipelineIdentification() {
8653
8786
  // Note: This is a 😐 implementation of [🚞]
@@ -9055,7 +9188,6 @@
9055
9188
  $pipelineJson.formfactorName = 'GENERIC';
9056
9189
  }
9057
9190
  // =============================================================
9058
- // TODO: [🍙] Maybe do reorder of `$pipelineJson` here
9059
9191
  return exportJson({
9060
9192
  name: 'pipelineJson',
9061
9193
  message: "Result of `precompilePipeline`",
@@ -10498,11 +10630,9 @@
10498
10630
  , ".json"));
10499
10631
  return [4 /*yield*/, isFileExisting(makedLibraryFilePath, tools.fs)];
10500
10632
  case 3:
10501
- if (!(_f.sent())) {
10502
- console.info(colors__default["default"].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.")));
10503
- }
10633
+ if (!(_f.sent())) ;
10504
10634
  else {
10505
- colors__default["default"].green("(In future, not implemented yet) Using your prebuild pipeline collection ".concat(makedLibraryFilePath));
10635
+ colors__default["default"].green("(In future, not implemented yet) Using your compiled pipeline collection ".concat(makedLibraryFilePath));
10506
10636
  // TODO: !! Implement;
10507
10637
  // TODO: [🌗]
10508
10638
  }
@@ -10522,10 +10652,10 @@
10522
10652
  // Note: First load all .book.json and then .book.md files
10523
10653
  // .book.json can be prepared so it is faster to load
10524
10654
  fileNames.sort(function (a, b) {
10525
- if (a.endsWith('.book.json') && b.endsWith('.book.md')) {
10655
+ if (a.endsWith('.json') && b.endsWith('.md')) {
10526
10656
  return -1;
10527
10657
  }
10528
- if (a.endsWith('.book.md') && b.endsWith('.book.json')) {
10658
+ if (a.endsWith('.md') && b.endsWith('.json')) {
10529
10659
  return 1;
10530
10660
  }
10531
10661
  return 0;
@@ -10574,7 +10704,7 @@
10574
10704
  // TODO: [👠] DRY
10575
10705
  if (pipeline.pipelineUrl === undefined) {
10576
10706
  if (isVerbose) {
10577
- console.info(colors__default["default"].red("Can not load pipeline from ".concat(fileName
10707
+ console.info(colors__default["default"].yellow("Can not load pipeline from ".concat(fileName
10578
10708
  .split('\\')
10579
10709
  .join('/'), " because of missing URL")));
10580
10710
  }
@@ -10708,7 +10838,7 @@
10708
10838
  * Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
10709
10839
  * Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
10710
10840
  *
10711
- * @public exported from `@promptbook/core`
10841
+ * @public exported from `@promptbook/editable`
10712
10842
  */
10713
10843
  function stringifyPipelineJson(pipeline) {
10714
10844
  if (!isSerializableAsJson(pipeline)) {