@promptbook/pdf 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 +140 -15
  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 +140 -15
  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
@@ -22,7 +22,7 @@
22
22
  *
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- var PROMPTBOOK_ENGINE_VERSION = '0.80.0-1';
25
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-5';
26
26
  /**
27
27
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
28
28
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -176,7 +176,7 @@
176
176
  function TODO_USE() {
177
177
  }
178
178
 
179
- 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"}];
179
+ 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"}];
180
180
 
181
181
  /**
182
182
  * Prettify the html code
@@ -475,6 +475,26 @@
475
475
  * @private within the repository - too low-level in comparison with other `MAX_...`
476
476
  */
477
477
  var LOOP_LIMIT = 1000;
478
+ /**
479
+ * Strings to represent various values in the context of parameter values
480
+ *
481
+ * @public exported from `@promptbook/utils`
482
+ */
483
+ var VALUE_STRINGS = {
484
+ empty: '(nothing; empty string)',
485
+ null: '(no value; null)',
486
+ undefined: '(unknown value; undefined)',
487
+ nan: '(not a number; NaN)',
488
+ infinity: '(infinity; ∞)',
489
+ negativeInfinity: '(negative infinity; -∞)',
490
+ unserializable: '(unserializable value)',
491
+ };
492
+ /**
493
+ * Small number limit
494
+ *
495
+ * @public exported from `@promptbook/utils`
496
+ */
497
+ var SMALL_NUMBER = 0.001;
478
498
  /**
479
499
  * Short time interval to prevent race conditions in milliseconds
480
500
  *
@@ -818,6 +838,7 @@
818
838
  * @public exported from `@promptbook/core`
819
839
  */
820
840
  var ORDER_OF_PIPELINE_JSON = [
841
+ // Note: [🍙] In this order will be pipeline serialized
821
842
  'title',
822
843
  'pipelineUrl',
823
844
  'bookVersion',
@@ -829,6 +850,7 @@
829
850
  'preparations',
830
851
  'knowledgeSources',
831
852
  'knowledgePieces',
853
+ 'sources', // <- TODO: [🧠] Where should the `sources` be
832
854
  ];
833
855
  /**
834
856
  * Nonce which is used for replacing things in strings
@@ -3220,6 +3242,30 @@
3220
3242
  return false;
3221
3243
  }
3222
3244
 
3245
+ /**
3246
+ * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3247
+ *
3248
+ * @private as default `fetch` function used in Promptbook scrapers
3249
+ */
3250
+ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
3251
+ var error_1;
3252
+ return __generator(this, function (_a) {
3253
+ switch (_a.label) {
3254
+ case 0:
3255
+ _a.trys.push([0, 2, , 3]);
3256
+ return [4 /*yield*/, fetch(url, init)];
3257
+ case 1: return [2 /*return*/, _a.sent()];
3258
+ case 2:
3259
+ error_1 = _a.sent();
3260
+ if (!(error_1 instanceof Error)) {
3261
+ throw error_1;
3262
+ }
3263
+ 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 "); }));
3264
+ case 3: return [2 /*return*/];
3265
+ }
3266
+ });
3267
+ }); };
3268
+
3223
3269
  /**
3224
3270
  * @@@
3225
3271
  *
@@ -3228,13 +3274,14 @@
3228
3274
  function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3229
3275
  var _a;
3230
3276
  return __awaiter(this, void 0, void 0, function () {
3231
- var sourceContent, name, _b, _c, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3232
- return __generator(this, function (_e) {
3233
- switch (_e.label) {
3277
+ var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
3278
+ return __generator(this, function (_f) {
3279
+ switch (_f.label) {
3234
3280
  case 0:
3281
+ _b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
3235
3282
  sourceContent = knowledgeSource.sourceContent;
3236
3283
  name = knowledgeSource.name;
3237
- _b = options || {}, _c = _b.rootDirname, rootDirname = _c === void 0 ? null : _c, _b.isVerbose;
3284
+ _c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
3238
3285
  if (!name) {
3239
3286
  name = sourceContentToName(sourceContent);
3240
3287
  }
@@ -3242,7 +3289,7 @@
3242
3289
  url = sourceContent;
3243
3290
  return [4 /*yield*/, fetch(url)];
3244
3291
  case 1:
3245
- response_1 = _e.sent();
3292
+ response_1 = _f.sent();
3246
3293
  mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
3247
3294
  return [2 /*return*/, {
3248
3295
  source: name,
@@ -3299,7 +3346,7 @@
3299
3346
  mimeType = extensionToMimeType(fileExtension || '');
3300
3347
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3301
3348
  case 3:
3302
- if (!(_e.sent())) {
3349
+ if (!(_f.sent())) {
3303
3350
  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 "); }));
3304
3351
  }
3305
3352
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
@@ -4327,16 +4374,94 @@
4327
4374
  * TODO: [🏢] Make this logic part of `JsonFormatDefinition` or `isValidJsonString`
4328
4375
  */
4329
4376
 
4377
+ /**
4378
+ * Format either small or big number
4379
+ *
4380
+ * @public exported from `@promptbook/utils`
4381
+ */
4382
+ function numberToString(value) {
4383
+ if (value === 0) {
4384
+ return '0';
4385
+ }
4386
+ else if (Number.isNaN(value)) {
4387
+ return VALUE_STRINGS.nan;
4388
+ }
4389
+ else if (value === Infinity) {
4390
+ return VALUE_STRINGS.infinity;
4391
+ }
4392
+ else if (value === -Infinity) {
4393
+ return VALUE_STRINGS.negativeInfinity;
4394
+ }
4395
+ for (var exponent = 0; exponent < 15; exponent++) {
4396
+ var factor = Math.pow(10, exponent);
4397
+ var valueRounded = Math.round(value * factor) / factor;
4398
+ if (Math.abs(value - valueRounded) / value < SMALL_NUMBER) {
4399
+ return valueRounded.toFixed(exponent);
4400
+ }
4401
+ }
4402
+ return value.toString();
4403
+ }
4404
+
4405
+ /**
4406
+ * Function `valueToString` will convert the given value to string
4407
+ * This is useful and used in the `templateParameters` function
4408
+ *
4409
+ * Note: This function is not just calling `toString` method
4410
+ * It's more complex and can handle this conversion specifically for LLM models
4411
+ * See `VALUE_STRINGS`
4412
+ *
4413
+ * Note: There are 2 similar functions
4414
+ * - `valueToString` converts value to string for LLM models as human-readable string
4415
+ * - `asSerializable` converts value to string to preserve full information to be able to convert it back
4416
+ *
4417
+ * @public exported from `@promptbook/utils`
4418
+ */
4419
+ function valueToString(value) {
4420
+ try {
4421
+ if (value === '') {
4422
+ return VALUE_STRINGS.empty;
4423
+ }
4424
+ else if (value === null) {
4425
+ return VALUE_STRINGS.null;
4426
+ }
4427
+ else if (value === undefined) {
4428
+ return VALUE_STRINGS.undefined;
4429
+ }
4430
+ else if (typeof value === 'string') {
4431
+ return value;
4432
+ }
4433
+ else if (typeof value === 'number') {
4434
+ return numberToString(value);
4435
+ }
4436
+ else if (value instanceof Date) {
4437
+ return value.toISOString();
4438
+ }
4439
+ else {
4440
+ return JSON.stringify(value);
4441
+ }
4442
+ }
4443
+ catch (error) {
4444
+ if (!(error instanceof Error)) {
4445
+ throw error;
4446
+ }
4447
+ console.error(error);
4448
+ return VALUE_STRINGS.unserializable;
4449
+ }
4450
+ }
4451
+
4330
4452
  /**
4331
4453
  * Replaces parameters in template with values from parameters object
4332
4454
  *
4455
+ * Note: This function is not places strings into string,
4456
+ * It's more complex and can handle this operation specifically for LLM models
4457
+ *
4333
4458
  * @param template the template with parameters in {curly} braces
4334
4459
  * @param parameters the object with parameters
4335
4460
  * @returns the template with replaced parameters
4336
4461
  * @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
4337
4462
  * @public exported from `@promptbook/utils`
4338
4463
  */
4339
- function replaceParameters(template, parameters) {
4464
+ function templateParameters(template, parameters) {
4340
4465
  var e_1, _a;
4341
4466
  try {
4342
4467
  for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -4362,7 +4487,7 @@
4362
4487
  var loopLimit = LOOP_LIMIT;
4363
4488
  var _loop_1 = function () {
4364
4489
  if (loopLimit-- < 0) {
4365
- throw new LimitReachedError('Loop limit reached during parameters replacement in `replaceParameters`');
4490
+ throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
4366
4491
  }
4367
4492
  var precol = match.groups.precol;
4368
4493
  var parameterName = match.groups.parameterName;
@@ -4379,7 +4504,7 @@
4379
4504
  if (parameterValue === undefined) {
4380
4505
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4381
4506
  }
4382
- parameterValue = parameterValue.toString();
4507
+ parameterValue = valueToString(parameterValue);
4383
4508
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4384
4509
  parameterValue = parameterValue
4385
4510
  .split('\n')
@@ -4614,7 +4739,7 @@
4614
4739
  }
4615
4740
  return [3 /*break*/, 24];
4616
4741
  case 2:
4617
- $ongoingTaskResult.$resultString = replaceParameters(preparedContent, parameters);
4742
+ $ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
4618
4743
  return [3 /*break*/, 25];
4619
4744
  case 3:
4620
4745
  modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
@@ -4737,8 +4862,8 @@
4737
4862
  _j = $ongoingTaskResult;
4738
4863
  return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
4739
4864
  promptTitle: task.title,
4740
- promptMessage: replaceParameters(task.description || '', parameters),
4741
- defaultValue: replaceParameters(preparedContent, parameters),
4865
+ promptMessage: templateParameters(task.description || '', parameters),
4866
+ defaultValue: templateParameters(preparedContent, parameters),
4742
4867
  // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
4743
4868
  placeholder: undefined,
4744
4869
  priority: priority,
@@ -4862,7 +4987,7 @@
4862
4987
  if (!isJokerAttempt &&
4863
4988
  task.taskType === 'PROMPT_TASK' &&
4864
4989
  $ongoingTaskResult.$prompt
4865
- // <- Note: [2] When some expected parameter is not defined, error will occur in replaceParameters
4990
+ // <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
4866
4991
  // In that case we don’t want to make a report about it because it’s not a llm execution error
4867
4992
  ) {
4868
4993
  // TODO: [🧠] Maybe put other taskTypes into report