@promptbook/pdf 0.81.0-22 → 0.81.0-23

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
@@ -134,32 +134,25 @@ We also have a community of developers and users of **Promptbook**:
134
134
  - [Landing page `ptbk.io`](https://ptbk.io)
135
135
  - [Github discussions](https://github.com/webgptorg/promptbook/discussions)
136
136
  - [LinkedIn `Promptbook`](https://linkedin.com/company/promptbook)
137
- - [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
137
+ - [Facebook `Promptbook`](https://www.facebook.com/61560776453536)
138
138
 
139
139
  And **Promptbook.studio** branded socials:
140
140
 
141
-
142
-
143
141
  - [Instagram `@promptbook.studio`](https://www.instagram.com/promptbook.studio/)
144
142
 
145
-
146
-
147
143
  And **Promptujeme** sub-brand:
148
144
 
149
- */Subbrand for Czech clients/*
150
-
151
-
145
+ _/Subbrand for Czech clients/_
152
146
 
153
147
  - [Promptujeme.cz](https://www.promptujeme.cz/)
154
148
  - [Facebook `Promptujeme`](https://www.facebook.com/promptujeme/)
155
149
 
156
-
157
150
  And **Promptbook.city** branded socials:
158
151
 
159
- */Sub-brand for images and graphics generated via Promptbook prompting/*
152
+ _/Sub-brand for images and graphics generated via Promptbook prompting/_
160
153
 
161
154
  - [Instagram `@promptbook.city`](https://www.instagram.com/promptbook.city/)
162
- - [Facebook `Promptbook City`](https://www.facebook.com/61565718625569)
155
+ - [Facebook `Promptbook City`](https://www.facebook.com/61565718625569)
163
156
 
164
157
 
165
158
 
@@ -293,11 +286,6 @@ Or you can install them separately:
293
286
 
294
287
  ## 📚 Dictionary
295
288
 
296
-
297
-
298
-
299
-
300
-
301
289
  ### 📚 Dictionary
302
290
 
303
291
  The following glossary is used to clarify certain concepts:
@@ -313,8 +301,6 @@ The following glossary is used to clarify certain concepts:
313
301
  - **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.
314
302
  - **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.
315
303
 
316
-
317
-
318
304
  _Note: Thos section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
319
305
 
320
306
  #### Promptbook core
@@ -375,8 +361,6 @@ _Note: Thos section is not complete dictionary, more list of general AI / LLM te
375
361
  - [👮 Agent adversary expectations](https://github.com/webgptorg/promptbook/discussions/39)
376
362
  - [view more](https://github.com/webgptorg/promptbook/discussions/categories/concepts)
377
363
 
378
-
379
-
380
364
  ### Terms specific to Promptbook TypeScript implementation
381
365
 
382
366
  - Anonymous mode
package/esm/index.es.js CHANGED
@@ -22,7 +22,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
22
22
  * @generated
23
23
  * @see https://github.com/webgptorg/promptbook
24
24
  */
25
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-21';
25
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-22';
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
@@ -178,6 +178,66 @@ function TODO_USE() {
178
178
 
179
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 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"}];
180
180
 
181
+ /**
182
+ * Function isValidJsonString will tell you if the string is valid JSON or not
183
+ *
184
+ * @public exported from `@promptbook/utils`
185
+ */
186
+ function isValidJsonString(value /* <- [👨‍⚖️] */) {
187
+ try {
188
+ JSON.parse(value);
189
+ return true;
190
+ }
191
+ catch (error) {
192
+ if (!(error instanceof Error)) {
193
+ throw error;
194
+ }
195
+ if (error.message.includes('Unexpected token')) {
196
+ return false;
197
+ }
198
+ return false;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
204
+ *
205
+ * @public exported from `@promptbook/core`
206
+ */
207
+ var ParseError = /** @class */ (function (_super) {
208
+ __extends(ParseError, _super);
209
+ function ParseError(message) {
210
+ var _this = _super.call(this, message) || this;
211
+ _this.name = 'ParseError';
212
+ Object.setPrototypeOf(_this, ParseError.prototype);
213
+ return _this;
214
+ }
215
+ return ParseError;
216
+ }(Error));
217
+ /**
218
+ * TODO: Maybe split `ParseError` and `ApplyError`
219
+ */
220
+
221
+ /**
222
+ * Function `validatePipelineString` will validate the if the string is a valid pipeline string
223
+ * 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.
224
+ *
225
+ * @param {string} pipelineString the candidate for a pipeline string
226
+ * @returns {PipelineString} the same string as input, but validated as valid
227
+ * @throws {ParseError} if the string is not a valid pipeline string
228
+ * @public exported from `@promptbook/core`
229
+ */
230
+ function validatePipelineString(pipelineString) {
231
+ if (isValidJsonString(pipelineString)) {
232
+ throw new ParseError('Expected a book, but got a JSON string');
233
+ }
234
+ // <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
235
+ return pipelineString;
236
+ }
237
+ /**
238
+ * TODO: [🧠][🈴] Where is the best location for this file
239
+ */
240
+
181
241
  /**
182
242
  * Prettify the html code
183
243
  *
@@ -244,7 +304,7 @@ function pipelineJsonToString(pipelineJson) {
244
304
  if (bookVersion !== "undefined") {
245
305
  commands.push("BOOK VERSION ".concat(bookVersion));
246
306
  }
247
- // TODO: [main] !!!!! This increases size of the bundle and is probbably not necessary
307
+ // TODO: [main] !!5 This increases size of the bundle and is probbably not necessary
248
308
  pipelineString = prettifyMarkdown(pipelineString);
249
309
  try {
250
310
  for (var _g = __values(parameters.filter(function (_a) {
@@ -392,12 +452,12 @@ function pipelineJsonToString(pipelineJson) {
392
452
  pipelineString += '```' + contentLanguage;
393
453
  pipelineString += '\n';
394
454
  pipelineString += spaceTrim$1(content);
395
- // <- TODO: [main] !!! Escape
455
+ // <- TODO: [main] !!3 Escape
396
456
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
397
457
  pipelineString += '\n';
398
458
  pipelineString += '```';
399
459
  pipelineString += '\n\n';
400
- pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!! If the parameter here has description, add it and use taskParameterJsonToString
460
+ pipelineString += "`-> {".concat(resultingParameterName, "}`"); // <- TODO: [main] !!3 If the parameter here has description, add it and use taskParameterJsonToString
401
461
  }
402
462
  }
403
463
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -407,7 +467,7 @@ function pipelineJsonToString(pipelineJson) {
407
467
  }
408
468
  finally { if (e_3) throw e_3.error; }
409
469
  }
410
- return pipelineString;
470
+ return validatePipelineString(pipelineString);
411
471
  }
412
472
  /**
413
473
  * @private internal utility of `pipelineJsonToString`
@@ -625,7 +685,7 @@ function $deepFreeze(objectValue) {
625
685
  /**
626
686
  * Make error report URL for the given error
627
687
  *
628
- * @private !!!!!!
688
+ * @private private within the repository
629
689
  */
630
690
  function getErrorReportUrl(error) {
631
691
  var report = {
@@ -776,7 +836,7 @@ function checkSerializableAsJson(options) {
776
836
  }
777
837
  /**
778
838
  * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
779
- * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
839
+ * TODO: [🧠][main] !!3 In-memory cache of same values to prevent multiple checks
780
840
  * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
781
841
  */
782
842
 
@@ -899,25 +959,6 @@ var RESERVED_PARAMETER_NAMES = exportJson({
899
959
  * Note: [💞] Ignore a discrepancy between file name and entity name
900
960
  */
901
961
 
902
- /**
903
- * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
904
- *
905
- * @public exported from `@promptbook/core`
906
- */
907
- var ParseError = /** @class */ (function (_super) {
908
- __extends(ParseError, _super);
909
- function ParseError(message) {
910
- var _this = _super.call(this, message) || this;
911
- _this.name = 'ParseError';
912
- Object.setPrototypeOf(_this, ParseError.prototype);
913
- return _this;
914
- }
915
- return ParseError;
916
- }(Error));
917
- /**
918
- * TODO: Maybe split `ParseError` and `ApplyError`
919
- */
920
-
921
962
  /**
922
963
  * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
923
964
  *
@@ -972,7 +1013,7 @@ function isValidPromptbookVersion(version) {
972
1013
  if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
973
1014
  return false;
974
1015
  }
975
- // <- TODO: [main] !!! Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
1016
+ // <- TODO: [main] !!3 Check isValidPromptbookVersion against PROMPTBOOK_ENGINE_VERSIONS
976
1017
  return true;
977
1018
  }
978
1019
 
@@ -1102,11 +1143,11 @@ function isValidPipelineUrl(url) {
1102
1143
  */
1103
1144
  function validatePipeline(pipeline) {
1104
1145
  if (IS_PIPELINE_LOGIC_VALIDATED) {
1105
- validatePipelineCore(pipeline);
1146
+ validatePipeline_InnerFunction(pipeline);
1106
1147
  }
1107
1148
  else {
1108
1149
  try {
1109
- validatePipelineCore(pipeline);
1150
+ validatePipeline_InnerFunction(pipeline);
1110
1151
  }
1111
1152
  catch (error) {
1112
1153
  if (!(error instanceof PipelineLogicError)) {
@@ -1120,7 +1161,7 @@ function validatePipeline(pipeline) {
1120
1161
  /**
1121
1162
  * @private internal function for `validatePipeline`
1122
1163
  */
1123
- function validatePipelineCore(pipeline) {
1164
+ function validatePipeline_InnerFunction(pipeline) {
1124
1165
  // TODO: [🧠] Maybe test if promptbook is a promise and make specific error case for that
1125
1166
  var e_1, _a, e_2, _b, e_3, _c;
1126
1167
  var pipelineIdentification = (function () {
@@ -1344,11 +1385,11 @@ function validatePipelineCore(pipeline) {
1344
1385
  _loop_3();
1345
1386
  }
1346
1387
  // Note: Check that formfactor is corresponding to the pipeline interface
1347
- // TODO: !!!!!! Implement this
1388
+ // TODO: !!6 Implement this
1348
1389
  // pipeline.formfactorName
1349
1390
  }
1350
1391
  /**
1351
- * TODO: !! [🧞‍♀️] Do not allow joker + foreach
1392
+ * TODO: [🧞‍♀️] Do not allow joker + foreach
1352
1393
  * TODO: [🧠] Work with promptbookVersion
1353
1394
  * TODO: Use here some json-schema, Zod or something similar and change it to:
1354
1395
  * > /**
@@ -1360,11 +1401,11 @@ function validatePipelineCore(pipeline) {
1360
1401
  * > ex port function validatePipeline(promptbook: really_unknown): asserts promptbook is PipelineJson {
1361
1402
  */
1362
1403
  /**
1363
- * TODO: [🧳][main] !!!! Validate that all examples match expectations
1364
- * TODO: [🧳][🐝][main] !!!! Validate that knowledge is valid (non-void)
1365
- * TODO: [🧳][main] !!!! Validate that persona can be used only with CHAT variant
1366
- * TODO: [🧳][main] !!!! Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
1367
- * TODO: [🧳][main] !!!! Validate that reserved parameter is not used as joker
1404
+ * TODO: [🧳][main] !!4 Validate that all examples match expectations
1405
+ * TODO: [🧳][🐝][main] !!4 Validate that knowledge is valid (non-void)
1406
+ * TODO: [🧳][main] !!4 Validate that persona can be used only with CHAT variant
1407
+ * TODO: [🧳][main] !!4 Validate that parameter with reserved name not used RESERVED_PARAMETER_NAMES
1408
+ * TODO: [🧳][main] !!4 Validate that reserved parameter is not used as joker
1368
1409
  * TODO: [🧠] Validation not only logic itself but imports around - files and websites and rerefenced pipelines exists
1369
1410
  * TODO: [🛠] Actions, instruments (and maybe knowledge) => Functions and tools
1370
1411
  */
@@ -1500,7 +1541,7 @@ var SimplePipelineCollection = /** @class */ (function () {
1500
1541
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
1501
1542
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1502
1543
  var existing = this.collection.get(pipeline.pipelineUrl);
1503
- 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 ")));
1544
+ 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 ")));
1504
1545
  }
1505
1546
  // Note: [🧠] Overwrite existing pipeline with the same URL
1506
1547
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -1845,7 +1886,7 @@ function isPipelinePrepared(pipeline) {
1845
1886
  return true;
1846
1887
  }
1847
1888
  /**
1848
- * TODO: [🔃][main] !! If the pipeline was prepared with different version or different set of models, prepare it once again
1889
+ * TODO: [🔃][main] If the pipeline was prepared with different version or different set of models, prepare it once again
1849
1890
  * TODO: [🐠] Maybe base this on `makeValidator`
1850
1891
  * TODO: [🧊] Pipeline can be partially prepared, this should return true ONLY if fully prepared
1851
1892
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -2610,10 +2651,10 @@ function preparePersona(personaDescription, tools, options) {
2610
2651
  });
2611
2652
  }
2612
2653
  /**
2613
- * TODO: [🔃][main] !! If the persona was prepared with different version or different set of models, prepare it once again
2614
- * TODO: [🏢] !! Check validity of `modelName` in pipeline
2615
- * TODO: [🏢] !! Check validity of `systemMessage` in pipeline
2616
- * TODO: [🏢] !! Check validity of `temperature` in pipeline
2654
+ * TODO: [🔃][main] If the persona was prepared with different version or different set of models, prepare it once again
2655
+ * TODO: [🏢] Check validity of `modelName` in pipeline
2656
+ * TODO: [🏢] Check validity of `systemMessage` in pipeline
2657
+ * TODO: [🏢] Check validity of `temperature` in pipeline
2617
2658
  */
2618
2659
 
2619
2660
  /**
@@ -3697,7 +3738,7 @@ function prepareTasks(pipeline, tools, options) {
3697
3738
  * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
3698
3739
  * TODO: [🧠] Add context to each task (if missing)
3699
3740
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
3700
- * TODO: [♨][main] !!! Prepare index the examples and maybe tasks
3741
+ * TODO: [♨][main] !!3 Prepare index the examples and maybe tasks
3701
3742
  * TODO: Write tests for `preparePipeline`
3702
3743
  * TODO: [🏏] Leverage the batch API and build queues @see https://platform.openai.com/docs/guides/batch
3703
3744
  * TODO: [🧊] In future one preparation can take data from previous preparation and save tokens and time
@@ -3760,17 +3801,10 @@ function preparePipeline(pipeline, tools, options) {
3760
3801
  _d.tools = tools,
3761
3802
  _d)]);
3762
3803
  return [4 /*yield*/, prepareTitleExecutor({
3763
- book: sources
3764
- .map(function (_a) {
3804
+ book: sources.map(function (_a) {
3765
3805
  var content = _a.content;
3766
3806
  return content;
3767
- })
3768
- .join('\n\n')
3769
- // TODO: !!!!!!! Parameters in parameters - DO NOT ALLOW, ESCAPE:
3770
- .split('{')
3771
- .join('[')
3772
- .split('}')
3773
- .join(']'),
3807
+ }).join('\n\n'),
3774
3808
  })];
3775
3809
  case 2:
3776
3810
  result = _e.sent();
@@ -4180,27 +4214,6 @@ var CsvFormatDefinition = {
4180
4214
  * TODO: [🏢] Allow to expect something inside CSV objects and other formats
4181
4215
  */
4182
4216
 
4183
- /**
4184
- * Function isValidJsonString will tell you if the string is valid JSON or not
4185
- *
4186
- * @public exported from `@promptbook/utils`
4187
- */
4188
- function isValidJsonString(value /* <- [👨‍⚖️] */) {
4189
- try {
4190
- JSON.parse(value);
4191
- return true;
4192
- }
4193
- catch (error) {
4194
- if (!(error instanceof Error)) {
4195
- throw error;
4196
- }
4197
- if (error.message.includes('Unexpected token')) {
4198
- return false;
4199
- }
4200
- return false;
4201
- }
4202
- }
4203
-
4204
4217
  /**
4205
4218
  * Definition for JSON format
4206
4219
  *
@@ -4575,6 +4588,8 @@ function templateParameters(template, parameters) {
4575
4588
  throw new PipelineExecutionError("Parameter `{".concat(parameterName, "}` is not defined"));
4576
4589
  }
4577
4590
  parameterValue = valueToString(parameterValue);
4591
+ // Escape curly braces in parameter values to prevent prompt-injection
4592
+ parameterValue = parameterValue.replace(/[{}]/g, '\\$&');
4578
4593
  if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
4579
4594
  parameterValue = parameterValue
4580
4595
  .split('\n')
@@ -4934,7 +4949,7 @@ function executeAttempts(options) {
4934
4949
  promptTitle: task.title,
4935
4950
  promptMessage: templateParameters(task.description || '', parameters),
4936
4951
  defaultValue: templateParameters(preparedContent, parameters),
4937
- // TODO: [🧠] !! Figure out how to define placeholder in .book.md file
4952
+ // TODO: [🧠] Figure out how to define placeholder in .book.md file
4938
4953
  placeholder: undefined,
4939
4954
  priority: priority,
4940
4955
  }))];
@@ -6019,12 +6034,12 @@ var MarkdownScraper = /** @class */ (function () {
6019
6034
  outputParameters = result.outputParameters;
6020
6035
  knowledgePiecesRaw = outputParameters.knowledgePieces;
6021
6036
  knowledgeTextPieces = (knowledgePiecesRaw || '').split('\n---\n');
6022
- // <- TODO: [main] !! Smarter split and filter out empty pieces
6037
+ // <- TODO: [main] Smarter split and filter out empty pieces
6023
6038
  if (isVerbose) {
6024
6039
  console.info('knowledgeTextPieces:', knowledgeTextPieces);
6025
6040
  }
6026
6041
  return [4 /*yield*/, Promise.all(
6027
- // TODO: [🪂] !! Do not send all at once but in chunks
6042
+ // TODO: [🪂] Do not send all at once but in chunks
6028
6043
  knowledgeTextPieces.map(function (knowledgeTextPiece, i) { return __awaiter(_this, void 0, void 0, function () {
6029
6044
  var name, title, knowledgePieceContent, keywords, index, titleResult, _a, titleRaw, keywordsResult, _b, keywordsRaw, embeddingResult, error_1;
6030
6045
  return __generator(this, function (_c) {