@promptbook/documents 0.81.0-22 → 0.81.0-24

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 (36) hide show
  1. package/README.md +4 -20
  2. package/esm/index.es.js +92 -77
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  6. package/esm/typings/src/cli/cli-commands/make.d.ts +1 -1
  7. package/esm/typings/src/cli/cli-commands/run.d.ts +2 -2
  8. package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +11 -0
  9. package/esm/typings/src/collection/constructors/createCollectionFromUrl.d.ts +1 -1
  10. package/esm/typings/src/commands/index.d.ts +1 -1
  11. package/esm/typings/src/config.d.ts +2 -2
  12. package/esm/typings/src/conversion/parsePipeline.d.ts +1 -1
  13. package/esm/typings/src/conversion/prettify/renderPipelineMermaidOptions.d.ts +3 -3
  14. package/esm/typings/src/conversion/validation/validatePipeline.d.ts +7 -7
  15. package/esm/typings/src/errors/utils/getErrorReportUrl.d.ts +1 -1
  16. package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -1
  17. package/esm/typings/src/llm-providers/anthropic-claude/createAnthropicClaudeExecutionTools.d.ts +2 -2
  18. package/esm/typings/src/llm-providers/anthropic-claude/playground/playground.d.ts +2 -2
  19. package/esm/typings/src/llm-providers/openai/playground/playground.d.ts +1 -1
  20. package/esm/typings/src/llm-providers/vercel/playground/playground.d.ts +1 -1
  21. package/esm/typings/src/other/templates/getBookTemplates.d.ts +1 -1
  22. package/esm/typings/src/personas/preparePersona.d.ts +4 -4
  23. package/esm/typings/src/pipeline/PipelineString.d.ts +0 -3
  24. package/esm/typings/src/pipeline/book-notation.d.ts +0 -1
  25. package/esm/typings/src/pipeline/isValidPipelineString.d.ts +3 -1
  26. package/esm/typings/src/pipeline/validatePipelineString.d.ts +14 -0
  27. package/esm/typings/src/prepare/isPipelinePrepared.d.ts +1 -1
  28. package/esm/typings/src/prepare/prepareTasks.d.ts +1 -1
  29. package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +1 -1
  30. package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +1 -1
  31. package/esm/typings/src/types/typeAliases.d.ts +8 -2
  32. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +1 -1
  33. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +1 -1
  34. package/package.json +2 -2
  35. package/umd/index.umd.js +92 -77
  36. package/umd/index.umd.js.map +1 -1
package/README.md CHANGED
@@ -135,32 +135,25 @@ We also have a community of developers and users of **Promptbook**:
135
135
  - [Landing page `ptbk.io`](https://ptbk.io)
136
136
  - [Github discussions](https://github.com/webgptorg/promptbook/discussions)
137
137
  - [LinkedIn `Promptbook`](https://linkedin.com/company/promptbook)
138
- - [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
138
+ - [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
139
139
 
140
140
  And **Promptbook.studio** branded socials:
141
141
 
142
-
143
-
144
142
  - [Instagram `@promptbook.studio`](https://www.instagram.com/promptbook.studio/)
145
143
 
146
-
147
-
148
144
  And **Promptujeme** sub-brand:
149
145
 
150
- */Subbrand for Czech clients/*
151
-
152
-
146
+ _/Subbrand for Czech clients/_
153
147
 
154
148
  - [Promptujeme.cz](https://www.promptujeme.cz/)
155
149
  - [Facebook `Promptujeme`](https://www.facebook.com/promptujeme/)
156
150
 
157
-
158
151
  And **Promptbook.city** branded socials:
159
152
 
160
- */Sub-brand for images and graphics generated via Promptbook prompting/*
153
+ _/Sub-brand for images and graphics generated via Promptbook prompting/_
161
154
 
162
155
  - [Instagram `@promptbook.city`](https://www.instagram.com/promptbook.city/)
163
- - [Facebook `Promptbook City`](https://www.facebook.com/61565718625569)
156
+ - [Facebook `Promptbook City`](https://www.facebook.com/61565718625569)
164
157
 
165
158
 
166
159
 
@@ -294,11 +287,6 @@ Or you can install them separately:
294
287
 
295
288
  ## 📚 Dictionary
296
289
 
297
-
298
-
299
-
300
-
301
-
302
290
  ### 📚 Dictionary
303
291
 
304
292
  The following glossary is used to clarify certain concepts:
@@ -314,8 +302,6 @@ The following glossary is used to clarify certain concepts:
314
302
  - **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
315
303
  - **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
316
304
 
317
-
318
-
319
305
  _Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
320
306
 
321
307
  #### Promptbook core
@@ -376,8 +362,6 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
376
362
  - [👮 Agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39)
377
363
  - [view more](https://github.com/webgptorg/promptbook/discussions/categories/concepts)
378
364
 
379
-
380
-
381
365
  ### Terms specific to Promptbook TypeScript implementation
382
366
 
383
367
  - Anonymous mode
package/esm/index.es.js CHANGED
@@ -25,7 +25,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-21';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-23';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -345,7 +345,7 @@ var MissingToolsError = /** @class */ (function (_super) {
345
345
  /**
346
346
  * Make error report URL for the given error
347
347
  *
348
- * @private !!!!!!
348
+ * @private private within the repository
349
349
  */
350
350
  function getErrorReportUrl(error) {
351
351
  var report = {
@@ -1116,6 +1116,66 @@ function getScraperIntermediateSource(source, options) {
1116
1116
 
1117
1117
  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 Knowledge-piece 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 - Write maximum ideally 2 words, maximum 5 words\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 Knowledge-piece 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 - Write maximum ideally 2 words, maximum 5 words\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 Persona",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 Persona\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"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-title.book.md",formfactorName:"GENERIC",parameters:[{name:"book",description:"The book to prepare the title for",isInput:true,isOutput:false},{name:"title",description:"Best title for the book",isInput:false,isOutput:true}],tasks:[{taskType:"PROMPT_TASK",name:"make-title",title:"Make title",content:"Make best title for given text which describes the task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon",resultingParameterName:"title",expectations:{words:{min:1,max:8},lines:{min:1,max:1}},dependentParameterNames:["book"]}],personas:[],preparations:[],knowledgeSources:[],knowledgePieces:[],sources:[{type:"BOOK",path:null,content:"# Prepare Title\n\n- PIPELINE URL `https://promptbook.studio/promptbook/prepare-title.book.md`\n- INPUT PARAMETER `{book}` The book to prepare the title for\n- OUTPUT PARAMETER `{title}` Best title for the book\n\n## Make title\n\n- EXPECT MIN 1 Word\n- EXPECT MAX 8 Words\n- EXPECT EXACTLY 1 Line\n\n```markdown\nMake best title for given text which describes the task:\n\n> {book}\n\n## Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Title starts with emoticon\n```\n\n`-> {title}`\n"}],sourceFile:"./books/prepare-title.book.md"}];
1118
1118
 
1119
+ /**
1120
+ * Function isValidJsonString will tell you if the string is valid JSON or not
1121
+ *
1122
+ * @public exported from `@promptbook/utils`
1123
+ */
1124
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1125
+ try {
1126
+ JSON.parse(value);
1127
+ return true;
1128
+ }
1129
+ catch (error) {
1130
+ if (!(error instanceof Error)) {
1131
+ throw error;
1132
+ }
1133
+ if (error.message.includes('Unexpected token')) {
1134
+ return false;
1135
+ }
1136
+ return false;
1137
+ }
1138
+ }
1139
+
1140
+ /**
1141
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
1142
+ *
1143
+ * @public exported from `@promptbook/core`
1144
+ */
1145
+ var ParseError = /** @class */ (function (_super) {
1146
+ __extends(ParseError, _super);
1147
+ function ParseError(message) {
1148
+ var _this = _super.call(this, message) || this;
1149
+ _this.name = 'ParseError';
1150
+ Object.setPrototypeOf(_this, ParseError.prototype);
1151
+ return _this;
1152
+ }
1153
+ return ParseError;
1154
+ }(Error));
1155
+ /**
1156
+ * TODO: Maybe split `ParseError` and `ApplyError`
1157
+ */
1158
+
1159
+ /**
1160
+ * Function `validatePipelineString` will validate the if the string is a valid pipeline string
1161
+ * It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
1162
+ *
1163
+ * @param {string} pipelineString the candidate for a pipeline string
1164
+ * @returns {PipelineString} the same string as input, but validated as valid
1165
+ * @throws {ParseError} if the string is not a valid pipeline string
1166
+ * @public exported from `@promptbook/core`
1167
+ */
1168
+ function validatePipelineString(pipelineString) {
1169
+ if (isValidJsonString(pipelineString)) {
1170
+ throw new ParseError('Expected a book, but got a JSON string');
1171
+ }
1172
+ // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
1173
+ return pipelineString;
1174
+ }
1175
+ /**
1176
+ * TODO: [🧠][🈴] Where is the best location for this file
1177
+ */
1178
+
1119
1179
  /**
1120
1180
  * Prettify the html code
1121
1181
  *
@@ -1182,7 +1242,7 @@ function pipelineJsonToString(pipelineJson) {
1182
1242
  if (bookVersion !== "undefined") {
1183
1243
  commands.push("BOOK VERSION ".concat(bookVersion));
1184
1244
  }
1185
- // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
1245
+ // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
1186
1246
  pipelineString = prettifyMarkdown(pipelineString);
1187
1247
  try {
1188
1248
  for (var _g = __values(parameters.filter(function (_a) {
@@ -1330,12 +1390,12 @@ function pipelineJsonToString(pipelineJson) {
1330
1390
  pipelineString += '```' + contentLanguage;
1331
1391
  pipelineString += '\n';
1332
1392
  pipelineString += spaceTrim$1(content);
1333
- // <- TODO: [main] !!! Escape
1393
+ // <- TODO: [main] !!3 Escape
1334
1394
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
1335
1395
  pipelineString += '\n';
1336
1396
  pipelineString += '```';
1337
1397
  pipelineString += '\n\n';
1338
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
1398
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
1339
1399
  }
1340
1400
  }
1341
1401
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -1345,7 +1405,7 @@ function pipelineJsonToString(pipelineJson) {
1345
1405
  }
1346
1406
  finally { if (e_3) throw e_3.error; }
1347
1407
  }
1348
- return pipelineString;
1408
+ return validatePipelineString(pipelineString);
1349
1409
  }
1350
1410
  /**
1351
1411
  * @private internal utility of `pipelineJsonToString`
@@ -1536,7 +1596,7 @@ function checkSerializableAsJson(options) {
1536
1596
  }
1537
1597
  /**
1538
1598
  * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
1539
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
1599
+ * TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
1540
1600
  * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
1541
1601
  */
1542
1602
 
@@ -1659,25 +1719,6 @@ var RESERVED_PARAMETER_NAMES = exportJson({
1659
1719
  * Note: [💞] Ignore a discrepancy between file name and entity name
1660
1720
  */
1661
1721
 
1662
- /**
1663
- * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
1664
- *
1665
- * @public exported from `@promptbook/core`
1666
- */
1667
- var ParseError = /** @class */ (function (_super) {
1668
- __extends(ParseError, _super);
1669
- function ParseError(message) {
1670
- var _this = _super.call(this, message) || this;
1671
- _this.name = 'ParseError';
1672
- Object.setPrototypeOf(_this, ParseError.prototype);
1673
- return _this;
1674
- }
1675
- return ParseError;
1676
- }(Error));
1677
- /**
1678
- * TODO: Maybe split `ParseError` and `ApplyError`
1679
- */
1680
-
1681
1722
  /**
1682
1723
  * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
1683
1724
  *
@@ -1732,7 +1773,7 @@ function isValidPromptbookVersion(version) {
1732
1773
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
1733
1774
  return false;
1734
1775
  }
1735
- // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1776
+ // <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1736
1777
  return true;
1737
1778
  }
1738
1779
 
@@ -1833,11 +1874,11 @@ function isValidPipelineUrl(url) {
1833
1874
  */
1834
1875
  function validatePipeline(pipeline) {
1835
1876
  if (IS_PIPELINE_LOGIC_VALIDATED) {
1836
- validatePipelineCore(pipeline);
1877
+ validatePipeline_InnerFunction(pipeline);
1837
1878
  }
1838
1879
  else {
1839
1880
  try {
1840
- validatePipelineCore(pipeline);
1881
+ validatePipeline_InnerFunction(pipeline);
1841
1882
  }
1842
1883
  catch (error) {
1843
1884
  if (!(error instanceof PipelineLogicError)) {
@@ -1851,7 +1892,7 @@ function validatePipeline(pipeline) {
1851
1892
  /**
1852
1893
  * @private internal function for `validatePipeline`
1853
1894
  */
1854
- function validatePipelineCore(pipeline) {
1895
+ function validatePipeline_InnerFunction(pipeline) {
1855
1896
  // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
1856
1897
  var e_1, _a, e_2, _b, e_3, _c;
1857
1898
  var pipelineIdentification = (function () {
@@ -2075,11 +2116,11 @@ function validatePipelineCore(pipeline) {
2075
2116
  _loop_3();
2076
2117
  }
2077
2118
  // Note: Check that formfactor is corresponding to the pipeline interface
2078
- // TODO: !!!!!! Implement this
2119
+ // TODO: !!6 Implement this
2079
2120
  // pipeline.formfactorName
2080
2121
  }
2081
2122
  /**
2082
- * TODO: !! [🧞‍♀️] Do not allow joker + foreach
2123
+ * TODO: [🧞‍♀️] Do not allow joker + foreach
2083
2124
  * TODO: [🧠] Work with promptbookVersion
2084
2125
  * TODO: Use here some json-schema, Zod or something similar and change it to:
2085
2126
  * > /**
@@ -2091,11 +2132,11 @@ function validatePipelineCore(pipeline) {
2091
2132
  * > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
2092
2133
  */
2093
2134
  /**
2094
- * TODO: [🧳][main] !!!! Validate that all examples match expectations
2095
- * TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
2096
- * TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
2097
- * TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
2098
- * TODO: [🧳][main] !!!! Validate that reserved parameter is not used as joker
2135
+ * TODO: [🧳][main] !!4 Validate that all examples match expectations
2136
+ * TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
2137
+ * TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
2138
+ * TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
2139
+ * TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
2099
2140
  * TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
2100
2141
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
2101
2142
  */
@@ -2231,7 +2272,7 @@ var SimplePipelineCollection = /** @class */ (function () {
2231
2272
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
2232
2273
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
2233
2274
  var existing = this.collection.get(pipeline.pipelineUrl);
2234
- throw new PipelineUrlError(spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
2275
+ throw new PipelineUrlError(spaceTrim("\n Pipeline with URL ".concat(pipeline.pipelineUrl, " is already in the collection \uD83C\uDF4E\n\n Conflicting files:\n ").concat(existing.sourceFile || 'Unknown', "\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: You have probably forgotten to run \"ptbk make\" to update the collection\n Note: Pipelines with the same URL are not allowed\n Only exepction is when the pipelines are identical\n\n ")));
2235
2276
  }
2236
2277
  // Note: [🧠] Overwrite existing pipeline with the same URL
2237
2278
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -2544,7 +2585,7 @@ function isPipelinePrepared(pipeline) {
2544
2585
  return true;
2545
2586
  }
2546
2587
  /**
2547
- * TODO: [🔃][main] !! If the pipeline was prepared with different version or different set of models, prepare it once again
2588
+ * TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
2548
2589
  * TODO: [🐠] Maybe base this on `makeValidator`
2549
2590
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
2550
2591
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -3309,10 +3350,10 @@ function preparePersona(personaDescription, tools, options) {
3309
3350
  });
3310
3351
  }
3311
3352
  /**
3312
- * TODO: [🔃][main] !! If the persona was prepared with different version or different set of models, prepare it once again
3313
- * TODO: [🏢] !! Check validity of `modelName` in pipeline
3314
- * TODO: [🏢] !! Check validity of `systemMessage` in pipeline
3315
- * TODO: [🏢] !! Check validity of `temperature` in pipeline
3353
+ * TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
3354
+ * TODO: [🏢] Check validity of `modelName` in pipeline
3355
+ * TODO: [🏢] Check validity of `systemMessage` in pipeline
3356
+ * TODO: [🏢] Check validity of `temperature` in pipeline
3316
3357
  */
3317
3358
 
3318
3359
  /**
@@ -3978,7 +4019,7 @@ function prepareTasks(pipeline, tools, options) {
3978
4019
  * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
3979
4020
  * TODO: [🧠] Add context to each task (if missing)
3980
4021
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
3981
- * TODO: [♨][main] !!! Prepare index the examples and maybe tasks
4022
+ * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
3982
4023
  * TODO: Write tests for `preparePipeline`
3983
4024
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3984
4025
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
@@ -4041,17 +4082,10 @@ function preparePipeline(pipeline, tools, options) {
4041
4082
  _d.tools = tools,
4042
4083
  _d)]);
4043
4084
  return [4 /*yield*/, prepareTitleExecutor({
4044
- book: sources
4045
- .map(function (_a) {
4085
+ book: sources.map(function (_a) {
4046
4086
  var content = _a.content;
4047
4087
  return content;
4048
- })
4049
- .join('\n\n')
4050
- // TODO: !!!!!!! Parameters in parameters - DO NOT ALLOW, ESCAPE:
4051
- .split('{')
4052
- .join('[')
4053
- .split('}')
4054
- .join(']'),
4088
+ }).join('\n\n'),
4055
4089
  })];
4056
4090
  case 2:
4057
4091
  result = _e.sent();
@@ -4461,27 +4495,6 @@ var CsvFormatDefinition = {
4461
4495
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
4462
4496
  */
4463
4497
 
4464
- /**
4465
- * Function isValidJsonString will tell you if the string is valid JSON or not
4466
- *
4467
- * @public exported from `@promptbook/utils`
4468
- */
4469
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
4470
- try {
4471
- JSON.parse(value);
4472
- return true;
4473
- }
4474
- catch (error) {
4475
- if (!(error instanceof Error)) {
4476
- throw error;
4477
- }
4478
- if (error.message.includes('Unexpected token')) {
4479
- return false;
4480
- }
4481
- return false;
4482
- }
4483
- }
4484
-
4485
4498
  /**
4486
4499
  * Definition for JSON format
4487
4500
  *
@@ -4856,6 +4869,8 @@ function templateParameters(template, parameters) {
4856
4869
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4857
4870
  }
4858
4871
  parameterValue = valueToString(parameterValue);
4872
+ // Escape curly braces in parameter values to prevent prompt-injection
4873
+ parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
4859
4874
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4860
4875
  parameterValue = parameterValue
4861
4876
  .split('\n')
@@ -5215,7 +5230,7 @@ function executeAttempts(options) {
5215
5230
  promptTitle: task.title,
5216
5231
  promptMessage: templateParameters(task.description || '', parameters),
5217
5232
  defaultValue: templateParameters(preparedContent, parameters),
5218
- // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
5233
+ // TODO: [🧠] Figure out how to define placeholder in .book.md file
5219
5234
  placeholder: undefined,
5220
5235
  priority: priority,
5221
5236
  }))];
@@ -6260,12 +6275,12 @@ var MarkdownScraper = /** @class */ (function () {
6260
6275
  outputParameters = result.outputParameters;
6261
6276
  knowledgePiecesRaw = outputParameters.knowledgePieces;
6262
6277
  knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
6263
- // <- TODO: [main] !! Smarter split and filter out empty pieces
6278
+ // <- TODO: [main] Smarter split and filter out empty pieces
6264
6279
  if (isVerbose) {
6265
6280
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
6266
6281
  }
6267
6282
  return [4 /*yield*/, Promise.all(
6268
- // TODO: [🪂] !! Do not send all at once but in chunks
6283
+ // TODO: [🪂] Do not send all at once but in chunks
6269
6284
  knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
6270
6285
  var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
6271
6286
  return __generator(this, function (_c) {