@promptbook/node 0.66.0 → 0.67.0-0

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 (58) hide show
  1. package/esm/index.es.js +429 -274
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +4 -4
  4. package/esm/typings/src/_packages/types.index.d.ts +7 -1
  5. package/esm/typings/src/_packages/utils.index.d.ts +14 -8
  6. package/esm/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +2 -0
  7. package/esm/typings/src/errors/{ReferenceError.d.ts → PipelineUrlError.d.ts} +2 -2
  8. package/esm/typings/src/errors/index.d.ts +27 -0
  9. package/esm/typings/src/errors/utils/ErrorJson.d.ts +20 -0
  10. package/esm/typings/src/errors/utils/deserializeError.d.ts +7 -0
  11. package/esm/typings/src/errors/utils/deserializeError.test.d.ts +1 -0
  12. package/esm/typings/src/errors/utils/serializeError.d.ts +7 -0
  13. package/esm/typings/src/errors/utils/serializeError.test.d.ts +1 -0
  14. package/esm/typings/src/execution/ExecutionTools.d.ts +4 -1
  15. package/esm/typings/src/execution/PipelineExecutor.d.ts +1 -47
  16. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +49 -0
  17. package/esm/typings/src/execution/PromptResult.d.ts +5 -4
  18. package/esm/typings/src/execution/PromptResultUsage.d.ts +4 -0
  19. package/esm/typings/src/execution/UncertainNumber.d.ts +1 -0
  20. package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +2 -2
  21. package/esm/typings/src/llm-providers/_common/utils/cache/CacheItem.d.ts +0 -1
  22. package/esm/typings/src/llm-providers/mocked/$fakeTextToExpectations.d.ts +2 -2
  23. package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +3 -3
  24. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -0
  25. package/esm/typings/src/llm-providers/remote/interfaces/PromptbookServer_Error.d.ts +2 -6
  26. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
  27. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +2 -2
  28. package/esm/typings/src/storage/_common/PromptbookStorage.d.ts +1 -1
  29. package/esm/typings/src/types/ModelRequirements.d.ts +5 -5
  30. package/esm/typings/src/types/PipelineJson/Expectations.d.ts +3 -1
  31. package/esm/typings/src/types/PipelineJson/KnowledgePieceJson.d.ts +2 -0
  32. package/esm/typings/src/types/PipelineJson/KnowledgeSourceJson.d.ts +4 -0
  33. package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +2 -0
  34. package/esm/typings/src/types/PipelineJson/PersonaJson.d.ts +4 -0
  35. package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +2 -0
  36. package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +1 -0
  37. package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +2 -0
  38. package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +2 -2
  39. package/esm/typings/src/types/PipelineJson/PromptTemplateParameterJson.d.ts +2 -0
  40. package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +1 -0
  41. package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +1 -0
  42. package/esm/typings/src/types/Prompt.d.ts +7 -7
  43. package/esm/typings/src/types/ScriptLanguage.d.ts +2 -0
  44. package/esm/typings/src/types/execution-report/ExecutionPromptReportJson.d.ts +24 -0
  45. package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -20
  46. package/esm/typings/src/types/typeAliases.d.ts +7 -0
  47. package/esm/typings/src/utils/environment/$getGlobalScope.d.ts +1 -4
  48. package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +17 -0
  49. package/esm/typings/src/utils/{deepFreeze.d.ts → serialization/$deepFreeze.d.ts} +0 -10
  50. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +27 -0
  51. package/esm/typings/src/utils/{clonePipeline.d.ts → serialization/clonePipeline.d.ts} +1 -1
  52. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +24 -0
  53. package/esm/typings/src/utils/serialization/isSerializableAsJson.test.d.ts +1 -0
  54. package/package.json +2 -2
  55. package/umd/index.umd.js +367 -212
  56. package/umd/index.umd.js.map +1 -1
  57. package/esm/typings/src/errors/VersionMismatchError.d.ts +0 -10
  58. /package/esm/typings/src/utils/{deepClone.d.ts → serialization/deepClone.d.ts} +0 -0
package/esm/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import colors from 'colors';
2
2
  import { stat, access, constants, readdir, readFile, writeFile, mkdir, unlink } from 'fs/promises';
3
3
  import { join as join$1, dirname } from 'path';
4
- import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
4
+ import spaceTrim$1, { spaceTrim } from 'spacetrim';
5
5
  import { format } from 'prettier';
6
6
  import parserHtml from 'prettier/parser-html';
7
7
  import hexEncoder from 'crypto-js/enc-hex';
@@ -13,7 +13,7 @@ import * as dotenv from 'dotenv';
13
13
  /**
14
14
  * The version of the Promptbook library
15
15
  */
16
- var PROMPTBOOK_VERSION = '0.66.0-9';
16
+ var PROMPTBOOK_VERSION = '0.66.0';
17
17
  // TODO: !!!! List here all the versions and annotate + put into script
18
18
 
19
19
  /*! *****************************************************************************
@@ -135,6 +135,26 @@ function __spreadArray(to, from, pack) {
135
135
  return to.concat(ar || Array.prototype.slice.call(from));
136
136
  }
137
137
 
138
+ /**
139
+ * Returns the same value that is passed as argument.
140
+ * No side effects.
141
+ *
142
+ * Note: It can be usefull for:
143
+ *
144
+ * 1) Leveling indentation
145
+ * 2) Putting always-true or always-false conditions without getting eslint errors
146
+ *
147
+ * @param value any values
148
+ * @returns the same values
149
+ * @private within the repository
150
+ */
151
+ function just(value) {
152
+ if (value === undefined) {
153
+ return undefined;
154
+ }
155
+ return value;
156
+ }
157
+
138
158
  /**
139
159
  * @@@
140
160
  *
@@ -165,42 +185,169 @@ function $deepFreeze(objectValue) {
165
185
  }
166
186
  return Object.freeze(objectValue);
167
187
  }
188
+ /**
189
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
190
+ */
191
+
192
+ /**
193
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
194
+ *
195
+ * @public exported from `@promptbook/core`
196
+ */
197
+ var UnexpectedError = /** @class */ (function (_super) {
198
+ __extends(UnexpectedError, _super);
199
+ function UnexpectedError(message) {
200
+ var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
201
+ _this.name = 'UnexpectedError';
202
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
203
+ return _this;
204
+ }
205
+ return UnexpectedError;
206
+ }(Error));
207
+
208
+ /**
209
+ * Checks if the value is [🚉] serializable as JSON
210
+ * If not, throws an UnexpectedError with a rich error message and tracking
211
+ *
212
+ * - Almost all primitives are serializable BUT:
213
+ * - `undefined` is not serializable
214
+ * - `NaN` is not serializable
215
+ * - Objects and arrays are serializable if all their properties are serializable
216
+ * - Functions are not serializable
217
+ * - Circular references are not serializable
218
+ * - `Date` objects are not serializable
219
+ * - `Map` and `Set` objects are not serializable
220
+ * - `RegExp` objects are not serializable
221
+ * - `Error` objects are not serializable
222
+ * - `Symbol` objects are not serializable
223
+ * - And much more...
224
+ *
225
+ * @throws UnexpectedError if the value is not serializable as JSON
226
+ * @public exported from `@promptbook/utils`
227
+ */
228
+ function checkSerializableAsJson(name, value) {
229
+ var e_1, _a;
230
+ if (value === undefined) {
231
+ throw new UnexpectedError("".concat(name, " is undefined"));
232
+ }
233
+ else if (value === null) {
234
+ return;
235
+ }
236
+ else if (typeof value === 'boolean') {
237
+ return;
238
+ }
239
+ else if (typeof value === 'number' && !isNaN(value)) {
240
+ return;
241
+ }
242
+ else if (typeof value === 'string') {
243
+ return;
244
+ }
245
+ else if (typeof value === 'symbol') {
246
+ throw new UnexpectedError("".concat(name, " is symbol"));
247
+ }
248
+ else if (typeof value === 'function') {
249
+ throw new UnexpectedError("".concat(name, " is function"));
250
+ }
251
+ else if (typeof value === 'object' && Array.isArray(value)) {
252
+ for (var i = 0; i < value.length; i++) {
253
+ checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
254
+ }
255
+ }
256
+ else if (typeof value === 'object') {
257
+ if (value instanceof Date) {
258
+ throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
259
+ }
260
+ else if (value instanceof Map) {
261
+ throw new UnexpectedError("".concat(name, " is Map"));
262
+ }
263
+ else if (value instanceof Set) {
264
+ throw new UnexpectedError("".concat(name, " is Set"));
265
+ }
266
+ else if (value instanceof RegExp) {
267
+ throw new UnexpectedError("".concat(name, " is RegExp"));
268
+ }
269
+ else if (value instanceof Error) {
270
+ throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
271
+ }
272
+ else {
273
+ try {
274
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
275
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
276
+ if (subValue === undefined) {
277
+ // Note: undefined in object is serializable - it is just omited
278
+ continue;
279
+ }
280
+ checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
281
+ }
282
+ }
283
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
284
+ finally {
285
+ try {
286
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
287
+ }
288
+ finally { if (e_1) throw e_1.error; }
289
+ }
290
+ try {
291
+ JSON.stringify(value); // <- TODO: [0]
292
+ }
293
+ catch (error) {
294
+ if (!(error instanceof Error)) {
295
+ throw error;
296
+ }
297
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
298
+ }
299
+ /*
300
+ TODO: [0] Is there some more elegant way to check circular references?
301
+ const seen = new Set();
302
+ const stack = [{ value }];
303
+ while (stack.length > 0) {
304
+ const { value } = stack.pop()!;
305
+ if (typeof value === 'object' && value !== null) {
306
+ if (seen.has(value)) {
307
+ throw new UnexpectedError(`${name} has circular reference`);
308
+ }
309
+ seen.add(value);
310
+ if (Array.isArray(value)) {
311
+ stack.push(...value.map((value) => ({ value })));
312
+ } else {
313
+ stack.push(...Object.values(value).map((value) => ({ value })));
314
+ }
315
+ }
316
+ }
317
+ */
318
+ return;
319
+ }
320
+ }
321
+ else {
322
+ throw new UnexpectedError("".concat(name, " is unknown"));
323
+ }
324
+ }
325
+ /**
326
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
327
+ * TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
328
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
329
+ */
330
+
168
331
  /**
169
332
  * @@@
170
333
  * @@@
171
334
  *
172
335
  * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
173
336
  *
337
+ * @param name - Name of the object for debugging purposes
338
+ * @param objectValue - Object to be deeply frozen
174
339
  * @returns The same object as the input, but deeply frozen
175
340
  * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
176
341
  */
177
- function deepFreezeWithSameType(objectValue) {
342
+ function $asDeeplyFrozenSerializableJson(name, objectValue) {
343
+ checkSerializableAsJson(name, objectValue);
178
344
  return $deepFreeze(objectValue);
179
345
  }
180
346
  /**
347
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
181
348
  * TODO: [🧠] Is there a way how to meaningfully test this utility
182
349
  */
183
350
 
184
- /**
185
- * Returns the same value that is passed as argument.
186
- * No side effects.
187
- *
188
- * Note: It can be usefull for:
189
- *
190
- * 1) Leveling indentation
191
- * 2) Putting always-true or always-false conditions without getting eslint errors
192
- *
193
- * @param value any values
194
- * @returns the same values
195
- * @private within the repository
196
- */
197
- function just(value) {
198
- if (value === undefined) {
199
- return undefined;
200
- }
201
- return value;
202
- }
203
-
204
351
  // <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
205
352
  /**
206
353
  * The maximum number of iterations for a loops
@@ -243,7 +390,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
243
390
  *
244
391
  * @public exported from `@promptbook/core`
245
392
  */
246
- var RESERVED_PARAMETER_NAMES = $deepFreeze([
393
+ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
247
394
  'content',
248
395
  'context',
249
396
  'knowledge',
@@ -486,7 +633,7 @@ function pipelineJsonToString(pipelineJson) {
486
633
  pipelineString += '\n\n';
487
634
  pipelineString += '```' + contentLanguage;
488
635
  pipelineString += '\n';
489
- pipelineString += spaceTrim(content);
636
+ pipelineString += spaceTrim$1(content);
490
637
  // <- TODO: !!! Escape
491
638
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
492
639
  pipelineString += '\n';
@@ -719,7 +866,7 @@ function forEachAsync(array, options, callbackfunction) {
719
866
  });
720
867
  }
721
868
 
722
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.0-9",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.66.0-9",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.66.0-9",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.66.0-9",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
869
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.66.0",parameters:[{name:"knowledgeContent",description:"Markdown document content",isInput:true,isOutput:false},{name:"knowledgePieces",description:"The knowledge JSON object",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, extract the important knowledge from the document.\n\n# Rules\n\n- Make pieces of information concise, clear, and easy to understand\n- One piece of information should be approximately 1 paragraph\n- Divide the paragraphs by markdown horizontal lines ---\n- Omit irrelevant information\n- Group redundant information\n- Write just extracted information, nothing else\n\n# The document\n\nTake information from this document:\n\n> {knowledgeContent}",dependentParameterNames:["knowledgeContent"],resultingParameterName:"knowledgePieces"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.66.0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"keywords",description:"Keywords separated by comma",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced data researcher, detect the important keywords in the document.\n\n# Rules\n\n- Write just keywords separated by comma\n\n# The document\n\nTake information from this document:\n\n> {knowledgePieceContent}",dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"keywords"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.66.0",parameters:[{name:"knowledgePieceContent",description:"The content",isInput:true,isOutput:false},{name:"title",description:"The title of the document",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"knowledge",title:"Knowledge",modelRequirements:{modelVariant:"CHAT",modelName:"claude-3-opus-20240229"},content:"You are experienced content creator, write best title for the document.\n\n# Rules\n\n- Write just title, nothing else\n- Title should be concise and clear\n- Write maximum 5 words for the title\n\n# The document\n\n> {knowledgePieceContent}",expectations:{words:{min:1,max:8}},dependentParameterNames:["knowledgePieceContent"],resultingParameterName:"title"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.66.0",parameters:[{name:"availableModelNames",description:"List of available model names separated by comma (,)",isInput:true,isOutput:false},{name:"personaDescription",description:"Description of the persona",isInput:true,isOutput:false},{name:"modelRequirements",description:"Specific requirements for the model",isInput:false,isOutput:true}],promptTemplates:[{blockType:"PROMPT_TEMPLATE",name:"make-model-requirements",title:"Make modelRequirements",modelRequirements:{modelVariant:"CHAT",modelName:"gpt-4-turbo"},content:"You are experienced AI engineer, you need to create virtual assistant.\nWrite\n\n## Sample\n\n```json\n{\n\"modelName\": \"gpt-4o\",\n\"systemMessage\": \"You are experienced AI engineer and helpfull assistant.\",\n\"temperature\": 0.7\n}\n```\n\n## Instructions\n\n### Option `modelName`\n\nPick from the following models:\n\n- {availableModelNames}\n\n### Option `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### Option `temperature`\n\nThe sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit.\n\nYou can pick a value between 0 and 2. For example:\n\n- `0.1`: Low temperature, extremely conservative and deterministic\n- `0.5`: Medium temperature, balanced between conservative and creative\n- `1.0`: High temperature, creative and bit random\n- `1.5`: Very high temperature, extremely creative and often chaotic and unpredictable\n- `2.0`: Maximum temperature, completely random and unpredictable, for some extreme creative use cases\n\n# The assistant\n\nTake this description of the persona:\n\n> {personaDescription}",expectFormat:"JSON",dependentParameterNames:["availableModelNames","personaDescription"],resultingParameterName:"modelRequirements"}],knowledgeSources:[],knowledgePieces:[],personas:[],preparations:[],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
723
870
 
724
871
  /**
725
872
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -753,22 +900,6 @@ var PipelineLogicError = /** @class */ (function (_super) {
753
900
  return PipelineLogicError;
754
901
  }(Error));
755
902
 
756
- /**
757
- * This error type indicates that the error should not happen and its last check before crashing with some other error
758
- *
759
- * @public exported from `@promptbook/core`
760
- */
761
- var UnexpectedError = /** @class */ (function (_super) {
762
- __extends(UnexpectedError, _super);
763
- function UnexpectedError(message) {
764
- var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This error should not happen.\n It's probbably a bug in the pipeline collection\n\n Please report issue:\n https://github.com/webgptorg/promptbook/issues\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
765
- _this.name = 'UnexpectedError';
766
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
767
- return _this;
768
- }
769
- return UnexpectedError;
770
- }(Error));
771
-
772
903
  /**
773
904
  * Tests if given string is valid semantic version
774
905
  *
@@ -954,36 +1085,36 @@ function validatePipeline(pipeline) {
954
1085
  })();
955
1086
  if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
956
1087
  // <- Note: [🚲]
957
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1088
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
958
1089
  }
959
1090
  if (!isValidPromptbookVersion(pipeline.promptbookVersion)) {
960
1091
  // <- Note: [🚲]
961
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1092
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
962
1093
  }
963
1094
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
964
1095
  if (!Array.isArray(pipeline.parameters)) {
965
1096
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
966
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1097
+ throw new ParsingError(spaceTrim(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.parameters` expected to be an array, but got ".concat(typeof pipeline.parameters, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
967
1098
  }
968
1099
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
969
1100
  if (!Array.isArray(pipeline.promptTemplates)) {
970
1101
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
971
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.promptTemplates` expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
1102
+ throw new ParsingError(spaceTrim(function (block) { return "\n Promptbook is valid JSON but with wrong structure\n\n `promptbook.promptTemplates` expected to be an array, but got ".concat(typeof pipeline.promptTemplates, "\n\n ").concat(block(pipelineIdentification), "\n "); }));
972
1103
  }
973
1104
  var _loop_1 = function (parameter) {
974
1105
  if (parameter.isInput && parameter.isOutput) {
975
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n\n Parameter {".concat(parameter.name, "} can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
1106
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n\n Parameter {".concat(parameter.name, "} can not be both input and output\n\n ").concat(block(pipelineIdentification), "\n "); }));
976
1107
  }
977
1108
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
978
1109
  if (!parameter.isInput &&
979
1110
  !parameter.isOutput &&
980
1111
  !pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
981
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
1112
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is created but not used\n\n You can declare {").concat(parameter.name, "} as output parameter by adding in the header:\n - OUTPUT PARAMETER `{").concat(parameter.name, "}` ").concat(parameter.description || '', "\n\n ").concat(block(pipelineIdentification), "\n\n "); }));
982
1113
  }
983
1114
  // Note: Testing that parameter is either input or result of some template
984
1115
  if (!parameter.isInput &&
985
1116
  !pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
986
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ").concat(block(pipelineIdentification), "\n "); }));
1117
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(parameter.name, "} is declared but not defined\n\n You can do one of these:\n - Remove declaration of {").concat(parameter.name, "}\n - Add prompt template that results in -> {").concat(parameter.name, "}\n\n ").concat(block(pipelineIdentification), "\n "); }));
987
1118
  }
988
1119
  };
989
1120
  try {
@@ -1011,20 +1142,20 @@ function validatePipeline(pipeline) {
1011
1142
  var _loop_2 = function (template) {
1012
1143
  var e_4, _h, e_5, _j;
1013
1144
  if (definedParameters.has(template.resultingParameterName)) {
1014
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1145
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1015
1146
  }
1016
1147
  if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
1017
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
1148
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter name {".concat(template.resultingParameterName, "} is reserved, please use different name\n\n ").concat(block(pipelineIdentification), "\n "); }));
1018
1149
  }
1019
1150
  definedParameters.add(template.resultingParameterName);
1020
1151
  if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
1021
1152
  if (!template.expectFormat &&
1022
1153
  !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1023
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
1154
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Joker parameters are used for {".concat(template.resultingParameterName, "} but no expectations are defined\n\n ").concat(block(pipelineIdentification), "\n "); }));
1024
1155
  }
1025
1156
  var _loop_4 = function (joker) {
1026
1157
  if (!template.dependentParameterNames.includes(joker)) {
1027
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1158
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(joker, "} is used for {").concat(template.resultingParameterName, "} as joker but not in `dependentParameterNames`\n\n ").concat(block(pipelineIdentification), "\n "); }));
1028
1159
  }
1029
1160
  };
1030
1161
  try {
@@ -1044,13 +1175,13 @@ function validatePipeline(pipeline) {
1044
1175
  if (template.expectations) {
1045
1176
  var _loop_5 = function (unit, min, max) {
1046
1177
  if (min !== undefined && max !== undefined && min > max) {
1047
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
1178
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation (=".concat(min, ") of ").concat(unit, " is higher than max expectation (=").concat(max, ")\n\n ").concat(block(pipelineIdentification), "\n "); }));
1048
1179
  }
1049
1180
  if (min !== undefined && min < 0) {
1050
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1181
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1051
1182
  }
1052
1183
  if (max !== undefined && max <= 0) {
1053
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1184
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1054
1185
  }
1055
1186
  };
1056
1187
  try {
@@ -1112,7 +1243,7 @@ function validatePipeline(pipeline) {
1112
1243
  var _loop_3 = function () {
1113
1244
  if (loopLimit-- < 0) {
1114
1245
  // Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
1115
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
1246
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
1116
1247
  }
1117
1248
  var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
1118
1249
  return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
@@ -1120,7 +1251,7 @@ function validatePipeline(pipeline) {
1120
1251
  if (currentlyResovedTemplates.length === 0) {
1121
1252
  throw new PipelineLogicError(
1122
1253
  // TODO: [🐎] DRY
1123
- spaceTrim$1(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
1254
+ spaceTrim(function (block) { return "\n\n Can not resolve some parameters:\n Either you are using a parameter that is not defined, or there are some circular dependencies.\n\n Can not resolve:\n ".concat(block(unresovedTemplates
1124
1255
  .map(function (_a) {
1125
1256
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1126
1257
  return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
@@ -1182,15 +1313,15 @@ var NotFoundError = /** @class */ (function (_super) {
1182
1313
  *
1183
1314
  * @public exported from `@promptbook/core`
1184
1315
  */
1185
- var ReferenceError$1 = /** @class */ (function (_super) {
1186
- __extends(ReferenceError, _super);
1187
- function ReferenceError(message) {
1316
+ var PipelineUrlError = /** @class */ (function (_super) {
1317
+ __extends(PipelineUrlError, _super);
1318
+ function PipelineUrlError(message) {
1188
1319
  var _this = _super.call(this, message) || this;
1189
- _this.name = 'ReferenceError';
1190
- Object.setPrototypeOf(_this, ReferenceError.prototype);
1320
+ _this.name = 'PipelineUrlError';
1321
+ Object.setPrototypeOf(_this, PipelineUrlError.prototype);
1191
1322
  return _this;
1192
1323
  }
1193
- return ReferenceError;
1324
+ return PipelineUrlError;
1194
1325
  }(Error));
1195
1326
 
1196
1327
  /**
@@ -1238,7 +1369,7 @@ function unpreparePipeline(pipeline) {
1238
1369
  delete promptTemplateUnprepared.preparedContent;
1239
1370
  return promptTemplateUnprepared;
1240
1371
  });
1241
- return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1372
+ return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1242
1373
  }
1243
1374
  /**
1244
1375
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -1274,7 +1405,7 @@ var SimplePipelineCollection = /** @class */ (function () {
1274
1405
  var pipeline = pipelines_1_1.value;
1275
1406
  // TODO: [👠] DRY
1276
1407
  if (pipeline.pipelineUrl === undefined) {
1277
- throw new ReferenceError$1(spaceTrim$1("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
1408
+ throw new PipelineUrlError(spaceTrim("\n Pipeline with name \"".concat(pipeline.title, "\" does not have defined URL\n\n File:\n ").concat(pipeline.sourceFile || 'Unknown', "\n\n Note: Pipelines without URLs are called anonymous pipelines\n They can be used as standalone pipelines, but they cannot be referenced by other pipelines\n And also they cannot be used in the pipeline collection\n\n ")));
1278
1409
  }
1279
1410
  // Note: [🐨]
1280
1411
  validatePipeline(pipeline);
@@ -1286,7 +1417,7 @@ var SimplePipelineCollection = /** @class */ (function () {
1286
1417
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
1287
1418
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1288
1419
  var existing = this.collection.get(pipeline.pipelineUrl);
1289
- throw new ReferenceError$1(spaceTrim$1("\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 ")));
1420
+ 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 ")));
1290
1421
  }
1291
1422
  // Note: [🧠] Overwrite existing pipeline with the same URL
1292
1423
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -1316,9 +1447,9 @@ var SimplePipelineCollection = /** @class */ (function () {
1316
1447
  var pipeline = this.collection.get(url);
1317
1448
  if (!pipeline) {
1318
1449
  if (this.listPipelines().length === 0) {
1319
- throw new NotFoundError(spaceTrim$1("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
1450
+ throw new NotFoundError(spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
1320
1451
  }
1321
- throw new NotFoundError(spaceTrim$1(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
1452
+ throw new NotFoundError(spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
1322
1453
  .map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
1323
1454
  .join('\n')), "\n\n "); }));
1324
1455
  }
@@ -1731,9 +1862,105 @@ var PipelineExecutionError = /** @class */ (function (_super) {
1731
1862
  }(Error));
1732
1863
 
1733
1864
  /**
1734
- * Asserts that the execution of a promptnook is successful
1865
+ * This error indicates that the pipeline collection cannot be propperly loaded
1735
1866
  *
1736
- * @param executionResult - The partial result of the promptnook execution
1867
+ * @public exported from `@promptbook/core`
1868
+ */
1869
+ var CollectionError = /** @class */ (function (_super) {
1870
+ __extends(CollectionError, _super);
1871
+ function CollectionError(message) {
1872
+ var _this = _super.call(this, message) || this;
1873
+ _this.name = 'CollectionError';
1874
+ Object.setPrototypeOf(_this, CollectionError.prototype);
1875
+ return _this;
1876
+ }
1877
+ return CollectionError;
1878
+ }(Error));
1879
+
1880
+ /**
1881
+ * This error type indicates that you try to use a feature that is not available in the current environment
1882
+ *
1883
+ * @public exported from `@promptbook/core`
1884
+ */
1885
+ var EnvironmentMismatchError = /** @class */ (function (_super) {
1886
+ __extends(EnvironmentMismatchError, _super);
1887
+ function EnvironmentMismatchError(message) {
1888
+ var _this = _super.call(this, message) || this;
1889
+ _this.name = 'EnvironmentMismatchError';
1890
+ Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
1891
+ return _this;
1892
+ }
1893
+ return EnvironmentMismatchError;
1894
+ }(Error));
1895
+
1896
+ /**
1897
+ * This error type indicates that some limit was reached
1898
+ *
1899
+ * @public exported from `@promptbook/core`
1900
+ */
1901
+ var LimitReachedError = /** @class */ (function (_super) {
1902
+ __extends(LimitReachedError, _super);
1903
+ function LimitReachedError(message) {
1904
+ var _this = _super.call(this, message) || this;
1905
+ _this.name = 'LimitReachedError';
1906
+ Object.setPrototypeOf(_this, LimitReachedError.prototype);
1907
+ return _this;
1908
+ }
1909
+ return LimitReachedError;
1910
+ }(Error));
1911
+
1912
+ /**
1913
+ * This error type indicates that some part of the code is not implemented yet
1914
+ *
1915
+ * @public exported from `@promptbook/core`
1916
+ */
1917
+ var NotYetImplementedError = /** @class */ (function (_super) {
1918
+ __extends(NotYetImplementedError, _super);
1919
+ function NotYetImplementedError(message) {
1920
+ var _this = _super.call(this, spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
1921
+ _this.name = 'NotYetImplementedError';
1922
+ Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
1923
+ return _this;
1924
+ }
1925
+ return NotYetImplementedError;
1926
+ }(Error));
1927
+
1928
+ /**
1929
+ * Index of all custom errors
1930
+ *
1931
+ * @public exported from `@promptbook/core`
1932
+ */
1933
+ var ERRORS = {
1934
+ CollectionError: CollectionError,
1935
+ EnvironmentMismatchError: EnvironmentMismatchError,
1936
+ LimitReachedError: LimitReachedError,
1937
+ NotFoundError: NotFoundError,
1938
+ NotYetImplementedError: NotYetImplementedError,
1939
+ ParsingError: ParsingError,
1940
+ PipelineExecutionError: PipelineExecutionError,
1941
+ PipelineLogicError: PipelineLogicError,
1942
+ PipelineUrlError: PipelineUrlError,
1943
+ UnexpectedError: UnexpectedError,
1944
+ // TODO: [🪑]> VersionMismatchError,
1945
+ };
1946
+
1947
+ /**
1948
+ * Deserializes the error object
1949
+ *
1950
+ * @public exported from `@promptbook/utils`
1951
+ */
1952
+ function deserializeError(error) {
1953
+ if (error.name === 'Error') {
1954
+ return new Error(error.message);
1955
+ }
1956
+ var CustomError = ERRORS[error.name];
1957
+ return new CustomError(error.message);
1958
+ }
1959
+
1960
+ /**
1961
+ * Asserts that the execution of a Promptbook is successful
1962
+ *
1963
+ * @param executionResult - The partial result of the Promptbook execution
1737
1964
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
1738
1965
  * @public exported from `@promptbook/core`
1739
1966
  */
@@ -1743,15 +1970,16 @@ function assertsExecutionSuccessful(executionResult) {
1743
1970
  return;
1744
1971
  }
1745
1972
  if (errors.length === 0) {
1746
- throw new PipelineExecutionError("Promptnook Execution failed because of unknown reason");
1973
+ throw new PipelineExecutionError("Promptbook Execution failed because of unknown reason");
1747
1974
  }
1748
1975
  else if (errors.length === 1) {
1749
- throw errors[0];
1976
+ throw deserializeError(errors[0]);
1750
1977
  }
1751
1978
  else {
1752
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors
1753
- .map(function (error, index) {
1754
- return spaceTrim$1(function (block) { return "\n Error ".concat(index + 1, ":\n ").concat(block(error.stack || error.message), "\n "); });
1979
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
1980
+ .map(function (_a, index) {
1981
+ var name = _a.name, stack = _a.stack, message = _a.message;
1982
+ return spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
1755
1983
  })
1756
1984
  .join('\n')), "\n "); }));
1757
1985
  }
@@ -1783,7 +2011,7 @@ function extractVariables(script) {
1783
2011
  var undefinedName = error.message.split(' ')[0];
1784
2012
  /*
1785
2013
  Note: Parsing the error
1786
- [ReferenceError: thing is not defined]
2014
+ [PipelineUrlError: thing is not defined]
1787
2015
  */
1788
2016
  if (!undefinedName) {
1789
2017
  throw error;
@@ -1801,7 +2029,7 @@ function extractVariables(script) {
1801
2029
  if (!(error instanceof Error)) {
1802
2030
  throw error;
1803
2031
  }
1804
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
2032
+ throw new ParsingError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
1805
2033
  }
1806
2034
  return variables;
1807
2035
  }
@@ -1888,6 +2116,23 @@ var ExpectError = /** @class */ (function (_super) {
1888
2116
  return ExpectError;
1889
2117
  }(Error));
1890
2118
 
2119
+ /**
2120
+ * Serializes an error into a [🚉] JSON-serializable object
2121
+ *
2122
+ * @public exported from `@promptbook/utils`
2123
+ */
2124
+ function serializeError(error) {
2125
+ var name = error.name, message = error.message, stack = error.stack;
2126
+ if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
2127
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
2128
+ }
2129
+ return {
2130
+ name: name,
2131
+ message: message,
2132
+ stack: stack,
2133
+ };
2134
+ }
2135
+
1891
2136
  /**
1892
2137
  * Function isValidJsonString will tell you if the string is valid JSON or not
1893
2138
  *
@@ -2127,7 +2372,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
2127
2372
  // 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
2128
2373
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
2129
2374
  // 3) ...
2130
- spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2375
+ spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2131
2376
  .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
2132
2377
  .join('\n')), "\n\n "); }));
2133
2378
  }
@@ -2135,7 +2380,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
2135
2380
  throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
2136
2381
  }
2137
2382
  else {
2138
- throw new PipelineExecutionError(spaceTrim(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
2383
+ throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n You have not provided any `LlmExecutionTools` that support model variant \"".concat(prompt.modelRequirements.modelVariant, "\n\n Available `LlmExecutionTools`:\n ").concat(block(_this.llmExecutionTools
2139
2384
  .map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
2140
2385
  .join('\n')), "\n\n "); }));
2141
2386
  }
@@ -2172,7 +2417,7 @@ function joinLlmExecutionTools() {
2172
2417
  llmExecutionTools[_i] = arguments[_i];
2173
2418
  }
2174
2419
  if (llmExecutionTools.length === 0) {
2175
- var warningMessage = spaceTrim("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
2420
+ var warningMessage = spaceTrim$1("\n You have not provided any `LlmExecutionTools`\n This means that you won't be able to execute any prompts that require large language models like GPT-4 or Anthropic's Claude.\n\n Technically, it's not an error, but it's probably not what you want because it does not make sense to use Promptbook without language models.\n ");
2176
2421
  // TODO: [🟥] Detect browser / node and make it colorfull
2177
2422
  console.warn(warningMessage);
2178
2423
  /*
@@ -2269,22 +2514,6 @@ function TODO_USE() {
2269
2514
  }
2270
2515
  }
2271
2516
 
2272
- /**
2273
- * This error type indicates that some limit was reached
2274
- *
2275
- * @public exported from `@promptbook/core`
2276
- */
2277
- var LimitReachedError = /** @class */ (function (_super) {
2278
- __extends(LimitReachedError, _super);
2279
- function LimitReachedError(message) {
2280
- var _this = _super.call(this, message) || this;
2281
- _this.name = 'LimitReachedError';
2282
- Object.setPrototypeOf(_this, LimitReachedError.prototype);
2283
- return _this;
2284
- }
2285
- return LimitReachedError;
2286
- }(Error));
2287
-
2288
2517
  /**
2289
2518
  * Replaces parameters in template with values from parameters object
2290
2519
  *
@@ -2584,7 +2813,7 @@ function createPipelineExecutor(options) {
2584
2813
  preparedPipeline = pipeline;
2585
2814
  }
2586
2815
  else if (isNotPreparedWarningSupressed !== true) {
2587
- console.warn(spaceTrim$1("\n Pipeline ".concat(pipeline.pipelineUrl || pipeline.sourceFile || pipeline.title, " is not prepared\n\n ").concat(pipeline.sourceFile, "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
2816
+ console.warn(spaceTrim("\n Pipeline ".concat(pipeline.pipelineUrl || pipeline.sourceFile || pipeline.title, " is not prepared\n\n ").concat(pipeline.sourceFile, "\n\n It will be prepared ad-hoc before the first execution and **returned as `preparedPipeline` in `PipelineExecutorResult`**\n But it is recommended to prepare the pipeline during collection preparation\n\n @see more at https://ptbk.io/prepare-pipeline\n ")));
2588
2817
  }
2589
2818
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2590
2819
  // TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
@@ -2670,7 +2899,6 @@ function createPipelineExecutor(options) {
2670
2899
  return __awaiter(this, void 0, void 0, function () {
2671
2900
  var name, title, priority, usedParameterNames, dependentParameterNames, definedParameters, _a, _b, _c, definedParameterNames, parameters, _d, _e, parameterName, prompt, chatResult, completionResult, embeddingResult, result, resultString, expectError, scriptPipelineExecutionErrors, maxAttempts, jokerParameterNames, preparedContent, attempt, isJokerAttempt, jokerParameterName, _f, _g, _h, _j, scriptTools, error_2, e_4_1, _k, _l, functionName, postprocessingError, _m, _o, scriptTools, error_3, e_5_1, e_6_1, error_4;
2672
2901
  var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
2673
- var _this = this;
2674
2902
  return __generator(this, function (_u) {
2675
2903
  switch (_u.label) {
2676
2904
  case 0:
@@ -2695,7 +2923,7 @@ function createPipelineExecutor(options) {
2695
2923
  usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
2696
2924
  dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
2697
2925
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
2698
- throw new UnexpectedError(spaceTrim$1("\n Dependent parameters are not consistent used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n ")));
2926
+ throw new UnexpectedError(spaceTrim("\n Dependent parameters are not consistent used parameters:\n\n Dependent parameters:\n ".concat(Array.from(dependentParameterNames).join(', '), "\n\n Used parameters:\n ").concat(Array.from(usedParameterNames).join(', '), "\n\n ")));
2699
2927
  }
2700
2928
  _b = (_a = Object).freeze;
2701
2929
  _c = [{}];
@@ -2720,7 +2948,7 @@ function createPipelineExecutor(options) {
2720
2948
  else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
2721
2949
  // Houston, we have a problem
2722
2950
  // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
2723
- throw new UnexpectedError(spaceTrim$1("\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ")));
2951
+ throw new UnexpectedError(spaceTrim("\n Parameter {".concat(parameterName, "} is NOT defined\n BUT used in template \"").concat(currentTemplate.title || currentTemplate.name, "\"\n\n This should be catched in `validatePipeline`\n\n ")));
2724
2952
  }
2725
2953
  }
2726
2954
  }
@@ -2791,71 +3019,8 @@ function createPipelineExecutor(options) {
2791
3019
  return name === currentTemplate.personaName;
2792
3020
  }) || {})), currentTemplate.expectations),
2793
3021
  expectFormat: currentTemplate.expectFormat,
2794
- postprocessing: (currentTemplate.postprocessingFunctionNames || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
2795
- var errors, _a, _b, scriptTools, error_5, e_8_1;
2796
- var e_8, _c;
2797
- return __generator(this, function (_d) {
2798
- switch (_d.label) {
2799
- case 0:
2800
- errors = [];
2801
- _d.label = 1;
2802
- case 1:
2803
- _d.trys.push([1, 8, 9, 10]);
2804
- _a = __values(arrayableToArray(tools.script)), _b = _a.next();
2805
- _d.label = 2;
2806
- case 2:
2807
- if (!!_b.done) return [3 /*break*/, 7];
2808
- scriptTools = _b.value;
2809
- _d.label = 3;
2810
- case 3:
2811
- _d.trys.push([3, 5, , 6]);
2812
- return [4 /*yield*/, scriptTools.execute({
2813
- scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
2814
- script: "".concat(functionName, "(result)"),
2815
- parameters: {
2816
- result: result || '',
2817
- // Note: No ...parametersForTemplate, because working with result only
2818
- },
2819
- })];
2820
- case 4: return [2 /*return*/, _d.sent()];
2821
- case 5:
2822
- error_5 = _d.sent();
2823
- if (!(error_5 instanceof Error)) {
2824
- throw error_5;
2825
- }
2826
- if (error_5 instanceof UnexpectedError) {
2827
- throw error_5;
2828
- }
2829
- errors.push(error_5);
2830
- return [3 /*break*/, 6];
2831
- case 6:
2832
- _b = _a.next();
2833
- return [3 /*break*/, 2];
2834
- case 7: return [3 /*break*/, 10];
2835
- case 8:
2836
- e_8_1 = _d.sent();
2837
- e_8 = { error: e_8_1 };
2838
- return [3 /*break*/, 10];
2839
- case 9:
2840
- try {
2841
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2842
- }
2843
- finally { if (e_8) throw e_8.error; }
2844
- return [7 /*endfinally*/];
2845
- case 10:
2846
- if (errors.length === 0) {
2847
- throw new PipelineExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
2848
- }
2849
- else if (errors.length === 1) {
2850
- throw errors[0];
2851
- }
2852
- else {
2853
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Postprocessing in LlmExecutionTools failed ".concat(errors.length, "x\n\n ").concat(block(errors.map(function (error) { return '- ' + error.message; }).join('\n\n')), "\n "); }));
2854
- }
2855
- }
2856
- });
2857
- }); }; }),
2858
- };
3022
+ postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
3023
+ }; // <- TODO: Not very good type guard
2859
3024
  _g = currentTemplate.modelRequirements.modelVariant;
2860
3025
  switch (_g) {
2861
3026
  case 'CHAT': return [3 /*break*/, 8];
@@ -2944,7 +3109,7 @@ function createPipelineExecutor(options) {
2944
3109
  throw scriptPipelineExecutionErrors[0];
2945
3110
  }
2946
3111
  else {
2947
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
3112
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
2948
3113
  .map(function (error) { return '- ' + error.message; })
2949
3114
  .join('\n\n')), "\n "); }));
2950
3115
  }
@@ -3080,13 +3245,13 @@ function createPipelineExecutor(options) {
3080
3245
  executionReport.promptExecutions.push({
3081
3246
  prompt: __assign({}, prompt),
3082
3247
  result: result || undefined,
3083
- error: expectError || undefined,
3248
+ error: expectError === null ? undefined : serializeError(expectError),
3084
3249
  });
3085
3250
  }
3086
3251
  return [7 /*endfinally*/];
3087
3252
  case 50:
3088
3253
  if (expectError !== null && attempt === maxAttempts - 1) {
3089
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
3254
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n LLM execution failed ".concat(maxExecutionAttempts, "x\n\n ---\n Last error ").concat((expectError === null || expectError === void 0 ? void 0 : expectError.name) || '', ":\n ").concat(block((expectError === null || expectError === void 0 ? void 0 : expectError.message) || ''), "\n\n Last result:\n ").concat(resultString, "\n ---\n "); }));
3090
3255
  }
3091
3256
  _u.label = 51;
3092
3257
  case 51:
@@ -3115,7 +3280,7 @@ function createPipelineExecutor(options) {
3115
3280
  });
3116
3281
  }
3117
3282
  function filterJustOutputParameters() {
3118
- var e_9, _a;
3283
+ var e_8, _a;
3119
3284
  var outputParameters = {};
3120
3285
  try {
3121
3286
  // Note: Filter ONLY output parameters
@@ -3132,12 +3297,12 @@ function createPipelineExecutor(options) {
3132
3297
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
3133
3298
  }
3134
3299
  }
3135
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
3300
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
3136
3301
  finally {
3137
3302
  try {
3138
3303
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3139
3304
  }
3140
- finally { if (e_9) throw e_9.error; }
3305
+ finally { if (e_8) throw e_8.error; }
3141
3306
  }
3142
3307
  return outputParameters;
3143
3308
  }
@@ -3174,11 +3339,11 @@ function createPipelineExecutor(options) {
3174
3339
  })), _b = _a.next(); !_b.done; _b = _a.next()) {
3175
3340
  parameter = _b.value;
3176
3341
  if (inputParameters[parameter.name] === undefined) {
3177
- return [2 /*return*/, deepFreezeWithSameType({
3342
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
3178
3343
  isSuccessful: false,
3179
3344
  errors: __spreadArray([
3180
3345
  new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
3181
- ], __read(errors), false),
3346
+ ], __read(errors), false).map(serializeError),
3182
3347
  warnings: [],
3183
3348
  executionReport: executionReport,
3184
3349
  outputParameters: {},
@@ -3204,12 +3369,12 @@ function createPipelineExecutor(options) {
3204
3369
  warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
3205
3370
  }
3206
3371
  else if (parameter.isInput === false) {
3207
- return { value: deepFreezeWithSameType({
3372
+ return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
3208
3373
  isSuccessful: false,
3209
3374
  errors: __spreadArray([
3210
3375
  new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
3211
- ], __read(errors), false),
3212
- warnings: warnings,
3376
+ ], __read(errors), false).map(serializeError),
3377
+ warnings: warnings.map(serializeError),
3213
3378
  executionReport: executionReport,
3214
3379
  outputParameters: {},
3215
3380
  usage: ZERO_USAGE,
@@ -3266,7 +3431,7 @@ function createPipelineExecutor(options) {
3266
3431
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
3267
3432
  throw new UnexpectedError(
3268
3433
  // TODO: [🐎] DRY
3269
- spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
3434
+ spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
3270
3435
  .map(function (_a) {
3271
3436
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
3272
3437
  return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
@@ -3316,10 +3481,10 @@ function createPipelineExecutor(options) {
3316
3481
  return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
3317
3482
  })), false));
3318
3483
  outputParameters_1 = filterJustOutputParameters();
3319
- return [2 /*return*/, deepFreezeWithSameType({
3484
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
3320
3485
  isSuccessful: false,
3321
- errors: __spreadArray([error_1], __read(errors), false),
3322
- warnings: warnings,
3486
+ errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
3487
+ warnings: warnings.map(serializeError),
3323
3488
  usage: usage_1,
3324
3489
  executionReport: executionReport,
3325
3490
  outputParameters: outputParameters_1,
@@ -3331,10 +3496,10 @@ function createPipelineExecutor(options) {
3331
3496
  return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
3332
3497
  })), false));
3333
3498
  outputParameters = filterJustOutputParameters();
3334
- return [2 /*return*/, deepFreezeWithSameType({
3499
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
3335
3500
  isSuccessful: true,
3336
- errors: errors,
3337
- warnings: warnings,
3501
+ errors: errors.map(serializeError),
3502
+ warnings: warnings.map(serializeError),
3338
3503
  usage: usage,
3339
3504
  executionReport: executionReport,
3340
3505
  outputParameters: outputParameters,
@@ -3420,8 +3585,8 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
3420
3585
  switch (_c.label) {
3421
3586
  case 0:
3422
3587
  name = "piece-".concat(i);
3423
- title = spaceTrim(knowledgeTextPiece.substring(0, 100));
3424
- knowledgePieceContent = spaceTrim(knowledgeTextPiece);
3588
+ title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
3589
+ knowledgePieceContent = spaceTrim$1(knowledgeTextPiece);
3425
3590
  keywords = [];
3426
3591
  index = [];
3427
3592
  _c.label = 1;
@@ -3431,7 +3596,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
3431
3596
  case 2:
3432
3597
  titleResult = _c.sent();
3433
3598
  _a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
3434
- title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
3599
+ title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
3435
3600
  name = titleToName(title);
3436
3601
  return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
3437
3602
  case 3:
@@ -3763,7 +3928,7 @@ function prepareTemplates(pipeline, options) {
3763
3928
  dependentParameterNames = template.dependentParameterNames;
3764
3929
  preparedContent = undefined;
3765
3930
  if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
3766
- preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
3931
+ preparedContent = spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
3767
3932
  // <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
3768
3933
  dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
3769
3934
  'knowledge',
@@ -3804,7 +3969,7 @@ function preparePipeline(pipeline, options) {
3804
3969
  return __awaiter(this, void 0, void 0, function () {
3805
3970
  var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
3806
3971
  /*
3807
- <- TODO: [🧠][0] `promptbookVersion` */
3972
+ <- TODO: [🧠][🪑] `promptbookVersion` */
3808
3973
  knowledgeSources /*
3809
3974
  <- TODO: [🧊] `knowledgePieces` */, personas /*
3810
3975
  <- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
@@ -3874,7 +4039,7 @@ function preparePipeline(pipeline, options) {
3874
4039
  // ----- /Templates preparation -----
3875
4040
  // Note: Count total usage
3876
4041
  currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
3877
- return [2 /*return*/, __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
4042
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
3878
4043
  }
3879
4044
  });
3880
4045
  });
@@ -3950,7 +4115,7 @@ var knowledgeCommandParser = {
3950
4115
  */
3951
4116
  parse: function (input) {
3952
4117
  var args = input.args;
3953
- var sourceContent = spaceTrim(args[0] || '');
4118
+ var sourceContent = spaceTrim$1(args[0] || '');
3954
4119
  if (sourceContent === '') {
3955
4120
  throw new ParsingError("Source is not defined");
3956
4121
  }
@@ -4066,8 +4231,8 @@ var personaCommandParser = {
4066
4231
  persona.description = personaDescription;
4067
4232
  return;
4068
4233
  }
4069
- console.warn(spaceTrim("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
4070
- persona.description += spaceTrim('\n\n' + personaDescription);
4234
+ console.warn(spaceTrim$1("\n\n Persona \"".concat(personaName, "\" is defined multiple times with different description:\n\n First definition:\n ").concat(persona.description, "\n\n Second definition:\n ").concat(personaDescription, "\n\n ")));
4235
+ persona.description += spaceTrim$1('\n\n' + personaDescription);
4071
4236
  },
4072
4237
  };
4073
4238
 
@@ -4254,7 +4419,7 @@ var blockCommandParser = {
4254
4419
  normalized = normalized.split('EXAMPLE').join('SAMPLE');
4255
4420
  var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
4256
4421
  if (blockTypes.length !== 1) {
4257
- throw new ParsingError(spaceTrim(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
4422
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Unknown block type in BLOCK command\n\n Supported block types are:\n ".concat(block(BlockTypes.join(', ')), "\n "); }));
4258
4423
  }
4259
4424
  var blockType = blockTypes[0];
4260
4425
  return {
@@ -4361,7 +4526,7 @@ var expectCommandParser = {
4361
4526
  /**
4362
4527
  * Description of the EXPECT command
4363
4528
  */
4364
- description: spaceTrim("\n Expect command describes the desired output of the prompt template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
4529
+ description: spaceTrim$1("\n Expect command describes the desired output of the prompt template (after post-processing)\n It can set limits for the maximum/minimum length of the output, measured in characters, words, sentences, paragraphs or some other shape of the output.\n "),
4365
4530
  /**
4366
4531
  * Link to discussion
4367
4532
  */
@@ -4454,7 +4619,7 @@ var expectCommandParser = {
4454
4619
  if (!(error instanceof Error)) {
4455
4620
  throw error;
4456
4621
  }
4457
- throw new ParsingError(spaceTrim(function (block) {
4622
+ throw new ParsingError(spaceTrim$1(function (block) {
4458
4623
  return "\n Invalid EXPECT command\n ".concat(block(error.message), ":\n ");
4459
4624
  }));
4460
4625
  }
@@ -4573,7 +4738,7 @@ var modelCommandParser = {
4573
4738
  // <- Note: [🤖]
4574
4739
  }
4575
4740
  else {
4576
- throw new ParsingError(spaceTrim(function (block) { return "\n Unknown model variant in command:\n\n Supported variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) { return "- ".concat(variantName); }).join('\n')), "\n "); }));
4741
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Unknown model variant in command:\n\n Supported variants are:\n ".concat(block(MODEL_VARIANTS.map(function (variantName) { return "- ".concat(variantName); }).join('\n')), "\n "); }));
4577
4742
  }
4578
4743
  }
4579
4744
  if (normalized.startsWith('MODEL_NAME')) {
@@ -4584,7 +4749,7 @@ var modelCommandParser = {
4584
4749
  };
4585
4750
  }
4586
4751
  else {
4587
- throw new ParsingError(spaceTrim(function (block) { return "\n Unknown model key in command.\n\n Supported model keys are:\n ".concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
4752
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n Unknown model key in command.\n\n Supported model keys are:\n ".concat(block(['variant', 'name'].join(', ')), "\n\n Example:\n\n - MODEL VARIANT Chat\n - MODEL NAME gpt-4\n "); }));
4588
4753
  }
4589
4754
  },
4590
4755
  };
@@ -5043,7 +5208,7 @@ function parseCommand(raw, usagePlace) {
5043
5208
  .map(removeMarkdownFormatting)
5044
5209
  .map(function (item) { return item.trim(); });
5045
5210
  if (items.length === 0 || items[0] === '') {
5046
- throw new ParsingError(spaceTrim$1(function (block) {
5211
+ throw new ParsingError(spaceTrim(function (block) {
5047
5212
  return "\n Malformed command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5048
5213
  }));
5049
5214
  }
@@ -5070,7 +5235,7 @@ function parseCommand(raw, usagePlace) {
5070
5235
  return command;
5071
5236
  }
5072
5237
  }
5073
- throw new ParsingError(spaceTrim$1(function (block) {
5238
+ throw new ParsingError(spaceTrim(function (block) {
5074
5239
  return "\n Malformed or unknown command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5075
5240
  }));
5076
5241
  }
@@ -5103,7 +5268,7 @@ function parseCommandVariant(input) {
5103
5268
  if (!(error instanceof ParsingError)) {
5104
5269
  throw error;
5105
5270
  }
5106
- throw new ParsingError(spaceTrim$1(function (block) {
5271
+ throw new ParsingError(spaceTrim(function (block) {
5107
5272
  return "\n Invalid ".concat(commandName, " command:\n ").concat(block(error.message), "\n\n - ").concat(raw, "\n\n Usage of ").concat(commandName, ":\n ").concat(block(commandParser.examples.map(function (example) { return "- ".concat(example); }).join('\n')), "\n\n All supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5108
5273
  }));
5109
5274
  }
@@ -5130,22 +5295,6 @@ function parseCommandVariant(input) {
5130
5295
  return null;
5131
5296
  }
5132
5297
 
5133
- /**
5134
- * This error type indicates that some part of the code is not implemented yet
5135
- *
5136
- * @public exported from `@promptbook/core`
5137
- */
5138
- var NotYetImplementedError = /** @class */ (function (_super) {
5139
- __extends(NotYetImplementedError, _super);
5140
- function NotYetImplementedError(message) {
5141
- var _this = _super.call(this, spaceTrim$1(function (block) { return "\n ".concat(block(message), "\n\n Note: This feature is not implemented yet but it will be soon.\n\n If you want speed up the implementation or just read more, look here:\n https://github.com/webgptorg/promptbook\n\n Or contact us on me@pavolhejny.com\n\n "); })) || this;
5142
- _this.name = 'NotYetImplementedError';
5143
- Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
5144
- return _this;
5145
- }
5146
- return NotYetImplementedError;
5147
- }(Error));
5148
-
5149
5298
  /**
5150
5299
  * Supported script languages
5151
5300
  *
@@ -5285,7 +5434,7 @@ function extractAllBlocksFromMarkdown(markdown) {
5285
5434
  function extractOneBlockFromMarkdown(markdown) {
5286
5435
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
5287
5436
  if (codeBlocks.length !== 1) {
5288
- throw new ParsingError(spaceTrim(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
5437
+ throw new ParsingError(spaceTrim$1(function (block) { return "\n There should be exactly 1 code block, found ".concat(codeBlocks.length, " code blocks\n\n ").concat(block(codeBlocks.map(function (block, i) { return "Block ".concat(i + 1, ":\n").concat(block.content); }).join('\n\n\n')), "\n "); }));
5289
5438
  }
5290
5439
  return codeBlocks[0];
5291
5440
  }
@@ -5306,7 +5455,7 @@ function parseMarkdownSection(value) {
5306
5455
  }
5307
5456
  var title = lines[0].replace(/^#+\s*/, '');
5308
5457
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
5309
- var content = spaceTrim(lines.slice(1).join('\n'));
5458
+ var content = spaceTrim$1(lines.slice(1).join('\n'));
5310
5459
  if (level < 1 || level > 6) {
5311
5460
  throw new ParsingError('Markdown section must have heading level between 1 and 6');
5312
5461
  }
@@ -5334,7 +5483,7 @@ function splitMarkdownIntoSections(markdown) {
5334
5483
  if (buffer.length === 0) {
5335
5484
  return;
5336
5485
  }
5337
- var section = spaceTrim(buffer.join('\n'));
5486
+ var section = spaceTrim$1(buffer.join('\n'));
5338
5487
  if (section === '') {
5339
5488
  return;
5340
5489
  }
@@ -5430,7 +5579,7 @@ function flattenMarkdown(markdown) {
5430
5579
  }
5431
5580
  finally { if (e_1) throw e_1.error; }
5432
5581
  }
5433
- return spaceTrim(flattenedMarkdown);
5582
+ return spaceTrim$1(flattenedMarkdown);
5434
5583
  }
5435
5584
  /**
5436
5585
  * TODO: [🏛] This can be part of markdown builder
@@ -5448,7 +5597,7 @@ function flattenMarkdown(markdown) {
5448
5597
  * @public exported from `@promptbook/markdown-utils`
5449
5598
  */
5450
5599
  function removeContentComments(content) {
5451
- return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
5600
+ return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
5452
5601
  }
5453
5602
 
5454
5603
  /**
@@ -5489,13 +5638,13 @@ function pipelineStringToJsonSync(pipelineString) {
5489
5638
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
5490
5639
  var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
5491
5640
  if (pipelineHead === undefined) {
5492
- throw new UnexpectedError(spaceTrim$1("\n Pipeline head is not defined\n\n This should never happen, because the pipeline already flattened\n "));
5641
+ throw new UnexpectedError(spaceTrim("\n Pipeline head is not defined\n\n This should never happen, because the pipeline already flattened\n "));
5493
5642
  }
5494
5643
  if (pipelineHead.level !== 1) {
5495
- throw new UnexpectedError(spaceTrim$1("\n Pipeline head is not h1\n\n This should never happen, because the pipeline already flattened\n "));
5644
+ throw new UnexpectedError(spaceTrim("\n Pipeline head is not h1\n\n This should never happen, because the pipeline already flattened\n "));
5496
5645
  }
5497
5646
  if (!pipelineSections.every(function (section) { return section.level === 2; })) {
5498
- throw new UnexpectedError(spaceTrim$1("\n Not every pipeline section is h2\n\n This should never happen, because the pipeline already flattened\n "));
5647
+ throw new UnexpectedError(spaceTrim("\n Not every pipeline section is h2\n\n This should never happen, because the pipeline already flattened\n "));
5499
5648
  }
5500
5649
  // =============================================================
5501
5650
  ///Note: 2️⃣ Function for defining parameters
@@ -5509,7 +5658,7 @@ function pipelineStringToJsonSync(pipelineString) {
5509
5658
  existingParameter.description &&
5510
5659
  existingParameter.description !== parameterDescription &&
5511
5660
  parameterDescription) {
5512
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
5661
+ throw new ParsingError(spaceTrim(function (block) { return "\n Parameter {".concat(parameterName, "} is defined multiple times with different description:\n\n First definition:\n ").concat(block(existingParameter.description || '[undefined]'), "\n\n Second definition:\n ").concat(block(parameterDescription || '[undefined]'), "\n "); }));
5513
5662
  }
5514
5663
  if (existingParameter) {
5515
5664
  if (parameterDescription) {
@@ -5535,7 +5684,7 @@ function pipelineStringToJsonSync(pipelineString) {
5535
5684
  description = description.split(/^>.*$/gm).join('');
5536
5685
  //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
5537
5686
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
5538
- description = spaceTrim$1(description);
5687
+ description = spaceTrim(description);
5539
5688
  if (description === '') {
5540
5689
  description = undefined;
5541
5690
  }
@@ -5606,7 +5755,7 @@ function pipelineStringToJsonSync(pipelineString) {
5606
5755
  if (resultingParameterName !== null) {
5607
5756
  return resultingParameterName;
5608
5757
  }
5609
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
5758
+ throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
5610
5759
  // TODO: Show code of invalid sections each time + DRY
5611
5760
  section.content
5612
5761
  .split('\n')
@@ -5621,7 +5770,7 @@ function pipelineStringToJsonSync(pipelineString) {
5621
5770
  description_1 = description_1.split(/^>.*$/gm).join('');
5622
5771
  //Note: Remove lists and return statement - TODO: [🎾]
5623
5772
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
5624
- description_1 = spaceTrim$1(description_1);
5773
+ description_1 = spaceTrim(description_1);
5625
5774
  if (description_1 === '') {
5626
5775
  description_1 = undefined;
5627
5776
  }
@@ -5705,7 +5854,7 @@ function pipelineStringToJsonSync(pipelineString) {
5705
5854
  break;
5706
5855
  case 'EXPECT_FORMAT':
5707
5856
  if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
5708
- throw new ParsingError(spaceTrim$1("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
5857
+ throw new ParsingError(spaceTrim("\n Expect format is already defined to \"".concat(templateJson.expectFormat, "\".\n Now you try to redefine it by \"").concat(command.format, "\".\n ")));
5709
5858
  }
5710
5859
  templateJson.expectFormat = command.format;
5711
5860
  break;
@@ -5762,7 +5911,7 @@ function pipelineStringToJsonSync(pipelineString) {
5762
5911
  throw new ParsingError('You must specify the language of the script in the prompt template');
5763
5912
  }
5764
5913
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
5765
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
5914
+ throw new ParsingError(spaceTrim(function (block) { return "\n Script language ".concat(language, " is not supported.\n\n Supported languages are:\n ").concat(block(SUPPORTED_SCRIPT_LANGUAGES.join(', ')), "\n\n "); }));
5766
5915
  }
5767
5916
  templateJson.contentLanguage = language;
5768
5917
  }
@@ -5837,7 +5986,7 @@ function pipelineStringToJsonSync(pipelineString) {
5837
5986
  }
5838
5987
  });
5839
5988
  // =============================================================
5840
- return pipelineJson;
5989
+ return $asDeeplyFrozenSerializableJson('pipelineJson', pipelineJson);
5841
5990
  }
5842
5991
  /**
5843
5992
  * TODO: !!!! Warn if used only sync version
@@ -5881,7 +6030,9 @@ function pipelineStringToJson(pipelineString, options) {
5881
6030
  case 1:
5882
6031
  pipelineJson = _a.sent();
5883
6032
  _a.label = 2;
5884
- case 2: return [2 /*return*/, pipelineJson];
6033
+ case 2:
6034
+ // Note: No need to use `$asDeeplyFrozenSerializableJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
6035
+ return [2 /*return*/, pipelineJson];
5885
6036
  }
5886
6037
  });
5887
6038
  });
@@ -5892,22 +6043,6 @@ function pipelineStringToJson(pipelineString, options) {
5892
6043
  * TODO: [🧠] Should be in generated JSON file GENERATOR_WARNING
5893
6044
  */
5894
6045
 
5895
- /**
5896
- * This error indicates that the pipeline collection cannot be propperly loaded
5897
- *
5898
- * @public exported from `@promptbook/core`
5899
- */
5900
- var CollectionError = /** @class */ (function (_super) {
5901
- __extends(CollectionError, _super);
5902
- function CollectionError(message) {
5903
- var _this = _super.call(this, message) || this;
5904
- _this.name = 'CollectionError';
5905
- Object.setPrototypeOf(_this, CollectionError.prototype);
5906
- return _this;
5907
- }
5908
- return CollectionError;
5909
- }(Error));
5910
-
5911
6046
  /**
5912
6047
  * Detects if the code is running in a Node.js environment
5913
6048
  *
@@ -6273,7 +6408,7 @@ function createCollectionFromDirectory(path, options) {
6273
6408
  }
6274
6409
  else {
6275
6410
  existing = collection.get(pipeline.pipelineUrl);
6276
- throw new ReferenceError(spaceTrim("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4F\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 ")));
6411
+ throw new PipelineUrlError(spaceTrim$1("\n Pipeline with URL \"".concat(pipeline.pipelineUrl, "\" is already in the collection \uD83C\uDF4F\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 ")));
6277
6412
  }
6278
6413
  }
6279
6414
  }
@@ -6283,7 +6418,7 @@ function createCollectionFromDirectory(path, options) {
6283
6418
  if (!(error_1 instanceof Error)) {
6284
6419
  throw error_1;
6285
6420
  }
6286
- wrappedErrorMessage = spaceTrim(function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
6421
+ wrappedErrorMessage = spaceTrim$1(function (block) { return "\n ".concat(error_1.name, " in pipeline ").concat(fileName.split('\\').join('/'), "\u2060:\n\n ").concat(block(error_1.message), "\n\n "); });
6287
6422
  if (isCrashedOnError) {
6288
6423
  throw new CollectionError(wrappedErrorMessage);
6289
6424
  }
@@ -6339,35 +6474,16 @@ function createCollectionFromDirectory(path, options) {
6339
6474
  * TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
6340
6475
  */
6341
6476
 
6342
- /**
6343
- * This error type indicates that you try to use a feature that is not available in the current environment
6344
- *
6345
- * @public exported from `@promptbook/core`
6346
- */
6347
- var EnvironmentMismatchError = /** @class */ (function (_super) {
6348
- __extends(EnvironmentMismatchError, _super);
6349
- function EnvironmentMismatchError(message) {
6350
- var _this = _super.call(this, message) || this;
6351
- _this.name = 'EnvironmentMismatchError';
6352
- Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
6353
- return _this;
6354
- }
6355
- return EnvironmentMismatchError;
6356
- }(Error));
6357
-
6358
6477
  /**
6359
6478
  * @@@
6360
6479
  *
6361
6480
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
6362
6481
  *
6363
- * @public exported from `@promptbook/utils`
6482
+ * @private internal function of `$Register`
6364
6483
  */
6365
6484
  function $getGlobalScope() {
6366
6485
  return Function('return this')();
6367
6486
  }
6368
- /***
6369
- * TODO: !!!!! Make private and promptbook registry from this
6370
- */
6371
6487
 
6372
6488
  /**
6373
6489
  * Register is @@@
@@ -6526,7 +6642,7 @@ function $registeredLlmToolsMessage() {
6526
6642
  });
6527
6643
  return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
6528
6644
  });
6529
- return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
6645
+ return spaceTrim$1(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
6530
6646
  .map(function (_a, i) {
6531
6647
  var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
6532
6648
  var more;
@@ -6574,7 +6690,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
6574
6690
  return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
6575
6691
  });
6576
6692
  if (registeredItem === undefined) {
6577
- throw new Error(spaceTrim(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
6693
+ throw new Error(spaceTrim$1(function (block) { return "\n There is no constructor for LLM provider `".concat(llmConfiguration.className, "` from `").concat(llmConfiguration.packageName, "`\n\n You have probably forgotten install and import the provider package.\n To fix this issue, you can:\n\n Install:\n\n > npm install ").concat(llmConfiguration.packageName, "\n\n And import:\n\n > import '").concat(llmConfiguration.packageName, "';\n\n\n ").concat(block($registeredLlmToolsMessage()), "\n "); }));
6578
6694
  }
6579
6695
  return registeredItem(__assign({ isVerbose: isVerbose }, llmConfiguration.options));
6580
6696
  });
@@ -6611,7 +6727,7 @@ function createLlmToolsFromEnv(options) {
6611
6727
  var configuration = createLlmToolsFromConfigurationFromEnv();
6612
6728
  if (configuration.length === 0) {
6613
6729
  // TODO: [🥃]
6614
- throw new Error(spaceTrim(function (block) { return "\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
6730
+ throw new Error(spaceTrim$1(function (block) { return "\n No LLM tools found in the environment\n\n Please set one of environment variables:\n - OPENAI_API_KEY\n - ANTHROPIC_CLAUDE_API_KEY\n\n ".concat(block($registeredLlmToolsMessage()), "}\n "); }));
6615
6731
  }
6616
6732
  return createLlmToolsFromConfiguration(configuration, options);
6617
6733
  }
@@ -6624,6 +6740,39 @@ function createLlmToolsFromEnv(options) {
6624
6740
  * TODO: This should be maybe not under `_common` but under `utils`
6625
6741
  */
6626
6742
 
6743
+ /**
6744
+ * Tests if the value is [🚉] serializable as JSON
6745
+ *
6746
+ * - Almost all primitives are serializable BUT:
6747
+ * - `undefined` is not serializable
6748
+ * - `NaN` is not serializable
6749
+ * - Objects and arrays are serializable if all their properties are serializable
6750
+ * - Functions are not serializable
6751
+ * - Circular references are not serializable
6752
+ * - `Date` objects are not serializable
6753
+ * - `Map` and `Set` objects are not serializable
6754
+ * - `RegExp` objects are not serializable
6755
+ * - `Error` objects are not serializable
6756
+ * - `Symbol` objects are not serializable
6757
+ * - And much more...
6758
+ *
6759
+ *
6760
+ * @public exported from `@promptbook/utils`
6761
+ */
6762
+ function isSerializableAsJson(value) {
6763
+ try {
6764
+ checkSerializableAsJson('', value);
6765
+ return true;
6766
+ }
6767
+ catch (error) {
6768
+ return false;
6769
+ }
6770
+ }
6771
+ /**
6772
+ * TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
6773
+ * TODO: [🧠][💺] Can be done this on type-level?
6774
+ */
6775
+
6627
6776
  /**
6628
6777
  * Stringify the PipelineJson with proper formatting
6629
6778
  *
@@ -6633,6 +6782,9 @@ function createLlmToolsFromEnv(options) {
6633
6782
  * @public exported from `@promptbook/core`
6634
6783
  */
6635
6784
  function stringifyPipelineJson(pipeline) {
6785
+ if (!isSerializableAsJson(pipeline)) {
6786
+ throw new UnexpectedError(spaceTrim$1("\n Cannot stringify the pipeline, because it is not serializable as JSON\n\n There can be multiple reasons:\n 1) The pipeline contains circular references\n 2) It is not a valid PipelineJson\n "));
6787
+ }
6636
6788
  var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
6637
6789
  for (var i = 0; i < LOOP_LIMIT; i++) {
6638
6790
  pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
@@ -6713,6 +6865,9 @@ var FilesStorage = /** @class */ (function () {
6713
6865
  switch (_a.label) {
6714
6866
  case 0:
6715
6867
  filename = this.getFilenameForKey(key);
6868
+ if (!isSerializableAsJson(value)) {
6869
+ throw new UnexpectedError("The \"".concat(key, "\" you want to store in JSON file is not serializable as JSON"));
6870
+ }
6716
6871
  fileContent = stringifyPipelineJson(value);
6717
6872
  return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
6718
6873
  case 1: