@promptbook/cli 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 +463 -306
  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 +1 -1
  55. package/umd/index.umd.js +383 -226
  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,5 +1,5 @@
1
1
  import commander from 'commander';
2
- import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
+ import spaceTrim$1, { spaceTrim } from 'spacetrim';
3
3
  import colors from 'colors';
4
4
  import { forTime } from 'waitasecond';
5
5
  import { stat, access, constants, readdir, readFile, writeFile, mkdir, unlink } from 'fs/promises';
@@ -20,7 +20,7 @@ import OpenAI from 'openai';
20
20
  /**
21
21
  * The version of the Promptbook library
22
22
  */
23
- var PROMPTBOOK_VERSION = '0.66.0-9';
23
+ var PROMPTBOOK_VERSION = '0.66.0';
24
24
  // TODO: !!!! List here all the versions and annotate + put into script
25
25
 
26
26
  /*! *****************************************************************************
@@ -167,6 +167,26 @@ var EnvironmentMismatchError = /** @class */ (function (_super) {
167
167
  */
168
168
  var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
169
169
 
170
+ /**
171
+ * Returns the same value that is passed as argument.
172
+ * No side effects.
173
+ *
174
+ * Note: It can be usefull for:
175
+ *
176
+ * 1) Leveling indentation
177
+ * 2) Putting always-true or always-false conditions without getting eslint errors
178
+ *
179
+ * @param value any values
180
+ * @returns the same values
181
+ * @private within the repository
182
+ */
183
+ function just(value) {
184
+ if (value === undefined) {
185
+ return undefined;
186
+ }
187
+ return value;
188
+ }
189
+
170
190
  /**
171
191
  * @@@
172
192
  *
@@ -197,42 +217,169 @@ function $deepFreeze(objectValue) {
197
217
  }
198
218
  return Object.freeze(objectValue);
199
219
  }
220
+ /**
221
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
222
+ */
223
+
224
+ /**
225
+ * This error type indicates that the error should not happen and its last check before crashing with some other error
226
+ *
227
+ * @public exported from `@promptbook/core`
228
+ */
229
+ var UnexpectedError = /** @class */ (function (_super) {
230
+ __extends(UnexpectedError, _super);
231
+ function UnexpectedError(message) {
232
+ 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;
233
+ _this.name = 'UnexpectedError';
234
+ Object.setPrototypeOf(_this, UnexpectedError.prototype);
235
+ return _this;
236
+ }
237
+ return UnexpectedError;
238
+ }(Error));
239
+
240
+ /**
241
+ * Checks if the value is [🚉] serializable as JSON
242
+ * If not, throws an UnexpectedError with a rich error message and tracking
243
+ *
244
+ * - Almost all primitives are serializable BUT:
245
+ * - `undefined` is not serializable
246
+ * - `NaN` is not serializable
247
+ * - Objects and arrays are serializable if all their properties are serializable
248
+ * - Functions are not serializable
249
+ * - Circular references are not serializable
250
+ * - `Date` objects are not serializable
251
+ * - `Map` and `Set` objects are not serializable
252
+ * - `RegExp` objects are not serializable
253
+ * - `Error` objects are not serializable
254
+ * - `Symbol` objects are not serializable
255
+ * - And much more...
256
+ *
257
+ * @throws UnexpectedError if the value is not serializable as JSON
258
+ * @public exported from `@promptbook/utils`
259
+ */
260
+ function checkSerializableAsJson(name, value) {
261
+ var e_1, _a;
262
+ if (value === undefined) {
263
+ throw new UnexpectedError("".concat(name, " is undefined"));
264
+ }
265
+ else if (value === null) {
266
+ return;
267
+ }
268
+ else if (typeof value === 'boolean') {
269
+ return;
270
+ }
271
+ else if (typeof value === 'number' && !isNaN(value)) {
272
+ return;
273
+ }
274
+ else if (typeof value === 'string') {
275
+ return;
276
+ }
277
+ else if (typeof value === 'symbol') {
278
+ throw new UnexpectedError("".concat(name, " is symbol"));
279
+ }
280
+ else if (typeof value === 'function') {
281
+ throw new UnexpectedError("".concat(name, " is function"));
282
+ }
283
+ else if (typeof value === 'object' && Array.isArray(value)) {
284
+ for (var i = 0; i < value.length; i++) {
285
+ checkSerializableAsJson("".concat(name, "[").concat(i, "]"), value[i]);
286
+ }
287
+ }
288
+ else if (typeof value === 'object') {
289
+ if (value instanceof Date) {
290
+ throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is Date\n\n Use `string_date_iso8601` instead\n ")));
291
+ }
292
+ else if (value instanceof Map) {
293
+ throw new UnexpectedError("".concat(name, " is Map"));
294
+ }
295
+ else if (value instanceof Set) {
296
+ throw new UnexpectedError("".concat(name, " is Set"));
297
+ }
298
+ else if (value instanceof RegExp) {
299
+ throw new UnexpectedError("".concat(name, " is RegExp"));
300
+ }
301
+ else if (value instanceof Error) {
302
+ throw new UnexpectedError(spaceTrim$1("\n ".concat(name, " is unserialized Error\n\n Use function `serializeError`\n ")));
303
+ }
304
+ else {
305
+ try {
306
+ for (var _b = __values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
307
+ var _d = __read(_c.value, 2), subName = _d[0], subValue = _d[1];
308
+ if (subValue === undefined) {
309
+ // Note: undefined in object is serializable - it is just omited
310
+ continue;
311
+ }
312
+ checkSerializableAsJson("".concat(name, ".").concat(subName), subValue);
313
+ }
314
+ }
315
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
316
+ finally {
317
+ try {
318
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
319
+ }
320
+ finally { if (e_1) throw e_1.error; }
321
+ }
322
+ try {
323
+ JSON.stringify(value); // <- TODO: [0]
324
+ }
325
+ catch (error) {
326
+ if (!(error instanceof Error)) {
327
+ throw error;
328
+ }
329
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n ".concat(name, " is not serializable\n\n ").concat(block(error.toString()), "\n "); }));
330
+ }
331
+ /*
332
+ TODO: [0] Is there some more elegant way to check circular references?
333
+ const seen = new Set();
334
+ const stack = [{ value }];
335
+ while (stack.length > 0) {
336
+ const { value } = stack.pop()!;
337
+ if (typeof value === 'object' && value !== null) {
338
+ if (seen.has(value)) {
339
+ throw new UnexpectedError(`${name} has circular reference`);
340
+ }
341
+ seen.add(value);
342
+ if (Array.isArray(value)) {
343
+ stack.push(...value.map((value) => ({ value })));
344
+ } else {
345
+ stack.push(...Object.values(value).map((value) => ({ value })));
346
+ }
347
+ }
348
+ }
349
+ */
350
+ return;
351
+ }
352
+ }
353
+ else {
354
+ throw new UnexpectedError("".concat(name, " is unknown"));
355
+ }
356
+ }
357
+ /**
358
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
359
+ * TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
360
+ * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
361
+ */
362
+
200
363
  /**
201
364
  * @@@
202
365
  * @@@
203
366
  *
204
367
  * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
205
368
  *
369
+ * @param name - Name of the object for debugging purposes
370
+ * @param objectValue - Object to be deeply frozen
206
371
  * @returns The same object as the input, but deeply frozen
207
372
  * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
208
373
  */
209
- function deepFreezeWithSameType(objectValue) {
374
+ function $asDeeplyFrozenSerializableJson(name, objectValue) {
375
+ checkSerializableAsJson(name, objectValue);
210
376
  return $deepFreeze(objectValue);
211
377
  }
212
378
  /**
379
+ * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
213
380
  * TODO: [🧠] Is there a way how to meaningfully test this utility
214
381
  */
215
382
 
216
- /**
217
- * Returns the same value that is passed as argument.
218
- * No side effects.
219
- *
220
- * Note: It can be usefull for:
221
- *
222
- * 1) Leveling indentation
223
- * 2) Putting always-true or always-false conditions without getting eslint errors
224
- *
225
- * @param value any values
226
- * @returns the same values
227
- * @private within the repository
228
- */
229
- function just(value) {
230
- if (value === undefined) {
231
- return undefined;
232
- }
233
- return value;
234
- }
235
-
236
383
  /**
237
384
  * Warning message for the generated sections and files files
238
385
  *
@@ -301,7 +448,7 @@ var REPLACING_NONCE = 'u$k42k%!V2zo34w7Fu#@QUHYPW';
301
448
  *
302
449
  * @public exported from `@promptbook/core`
303
450
  */
304
- var RESERVED_PARAMETER_NAMES = $deepFreeze([
451
+ var RESERVED_PARAMETER_NAMES = $asDeeplyFrozenSerializableJson('RESERVED_PARAMETER_NAMES', [
305
452
  'content',
306
453
  'context',
307
454
  'knowledge',
@@ -354,7 +501,7 @@ var IS_VERBOSE = false;
354
501
  function initializeAboutCommand(program) {
355
502
  var _this = this;
356
503
  var makeCommand = program.command('about');
357
- makeCommand.description(spaceTrim("\n Tells about Promptbook CLI and its abilities\n "));
504
+ makeCommand.description(spaceTrim$1("\n Tells about Promptbook CLI and its abilities\n "));
358
505
  makeCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
359
506
  return __generator(this, function (_a) {
360
507
  console.info(colors.cyan("Promptbook"));
@@ -379,7 +526,7 @@ function initializeAboutCommand(program) {
379
526
  function initializeHelloCommand(program) {
380
527
  var _this = this;
381
528
  var helloCommand = program.command('hello');
382
- helloCommand.description(spaceTrim("\n Just command for testing\n "));
529
+ helloCommand.description(spaceTrim$1("\n Just command for testing\n "));
383
530
  helloCommand.argument('[name]', 'Your name', 'Paul');
384
531
  helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
385
532
  helloCommand.action(function (name, _a) {
@@ -641,7 +788,7 @@ function pipelineJsonToString(pipelineJson) {
641
788
  pipelineString += '\n\n';
642
789
  pipelineString += '```' + contentLanguage;
643
790
  pipelineString += '\n';
644
- pipelineString += spaceTrim(content);
791
+ pipelineString += spaceTrim$1(content);
645
792
  // <- TODO: !!! Escape
646
793
  // <- TODO: [🧠] Some clear strategy how to spaceTrim the blocks
647
794
  pipelineString += '\n';
@@ -874,7 +1021,7 @@ function forEachAsync(array, options, callbackfunction) {
874
1021
  });
875
1022
  }
876
1023
 
877
- 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"}];
1024
+ 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"}];
878
1025
 
879
1026
  /**
880
1027
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -908,22 +1055,6 @@ var PipelineLogicError = /** @class */ (function (_super) {
908
1055
  return PipelineLogicError;
909
1056
  }(Error));
910
1057
 
911
- /**
912
- * This error type indicates that the error should not happen and its last check before crashing with some other error
913
- *
914
- * @public exported from `@promptbook/core`
915
- */
916
- var UnexpectedError = /** @class */ (function (_super) {
917
- __extends(UnexpectedError, _super);
918
- function UnexpectedError(message) {
919
- 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;
920
- _this.name = 'UnexpectedError';
921
- Object.setPrototypeOf(_this, UnexpectedError.prototype);
922
- return _this;
923
- }
924
- return UnexpectedError;
925
- }(Error));
926
-
927
1058
  /**
928
1059
  * Tests if given string is valid semantic version
929
1060
  *
@@ -1109,36 +1240,36 @@ function validatePipeline(pipeline) {
1109
1240
  })();
1110
1241
  if (pipeline.pipelineUrl !== undefined && !isValidPipelineUrl(pipeline.pipelineUrl)) {
1111
1242
  // <- Note: [🚲]
1112
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1243
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid promptbook URL \"".concat(pipeline.pipelineUrl, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1113
1244
  }
1114
1245
  if (!isValidPromptbookVersion(pipeline.promptbookVersion)) {
1115
1246
  // <- Note: [🚲]
1116
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1247
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Invalid Promptbook Version \"".concat(pipeline.promptbookVersion, "\"\n\n ").concat(block(pipelineIdentification), "\n "); }));
1117
1248
  }
1118
1249
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1119
1250
  if (!Array.isArray(pipeline.parameters)) {
1120
1251
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1121
- 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 "); }));
1252
+ 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 "); }));
1122
1253
  }
1123
1254
  // TODO: [🧠] Maybe do here some propper JSON-schema / ZOD checking
1124
1255
  if (!Array.isArray(pipeline.promptTemplates)) {
1125
1256
  // TODO: [🧠] what is the correct error tp throw - maybe PromptbookSchemaError
1126
- 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 "); }));
1257
+ 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 "); }));
1127
1258
  }
1128
1259
  var _loop_1 = function (parameter) {
1129
1260
  if (parameter.isInput && parameter.isOutput) {
1130
- 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 "); }));
1261
+ 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 "); }));
1131
1262
  }
1132
1263
  // Note: Testing that parameter is either intermediate or output BUT not created and unused
1133
1264
  if (!parameter.isInput &&
1134
1265
  !parameter.isOutput &&
1135
1266
  !pipeline.promptTemplates.some(function (template) { return template.dependentParameterNames.includes(parameter.name); })) {
1136
- 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 "); }));
1267
+ 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 "); }));
1137
1268
  }
1138
1269
  // Note: Testing that parameter is either input or result of some template
1139
1270
  if (!parameter.isInput &&
1140
1271
  !pipeline.promptTemplates.some(function (template) { return template.resultingParameterName === parameter.name; })) {
1141
- 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 "); }));
1272
+ 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 "); }));
1142
1273
  }
1143
1274
  };
1144
1275
  try {
@@ -1166,20 +1297,20 @@ function validatePipeline(pipeline) {
1166
1297
  var _loop_2 = function (template) {
1167
1298
  var e_4, _h, e_5, _j;
1168
1299
  if (definedParameters.has(template.resultingParameterName)) {
1169
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1300
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Parameter {".concat(template.resultingParameterName, "} is defined multiple times\n\n ").concat(block(pipelineIdentification), "\n "); }));
1170
1301
  }
1171
1302
  if (RESERVED_PARAMETER_NAMES.includes(template.resultingParameterName)) {
1172
- 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 "); }));
1303
+ 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 "); }));
1173
1304
  }
1174
1305
  definedParameters.add(template.resultingParameterName);
1175
1306
  if (template.jokerParameterNames && template.jokerParameterNames.length > 0) {
1176
1307
  if (!template.expectFormat &&
1177
1308
  !template.expectations /* <- TODO: Require at least 1 -> min <- expectation to use jokers */) {
1178
- 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 "); }));
1309
+ 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 "); }));
1179
1310
  }
1180
1311
  var _loop_4 = function (joker) {
1181
1312
  if (!template.dependentParameterNames.includes(joker)) {
1182
- 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 "); }));
1313
+ 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 "); }));
1183
1314
  }
1184
1315
  };
1185
1316
  try {
@@ -1199,13 +1330,13 @@ function validatePipeline(pipeline) {
1199
1330
  if (template.expectations) {
1200
1331
  var _loop_5 = function (unit, min, max) {
1201
1332
  if (min !== undefined && max !== undefined && min > max) {
1202
- 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 "); }));
1333
+ 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 "); }));
1203
1334
  }
1204
1335
  if (min !== undefined && min < 0) {
1205
- 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 "); }));
1336
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Min expectation of ".concat(unit, " must be zero or positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1206
1337
  }
1207
1338
  if (max !== undefined && max <= 0) {
1208
- throw new PipelineLogicError(spaceTrim$1(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1339
+ throw new PipelineLogicError(spaceTrim(function (block) { return "\n Max expectation of ".concat(unit, " must be positive\n\n ").concat(block(pipelineIdentification), "\n "); }));
1209
1340
  }
1210
1341
  };
1211
1342
  try {
@@ -1267,7 +1398,7 @@ function validatePipeline(pipeline) {
1267
1398
  var _loop_3 = function () {
1268
1399
  if (loopLimit-- < 0) {
1269
1400
  // Note: Really UnexpectedError not LimitReachedError - this should not happen and be caught below
1270
- 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 "); }));
1401
+ throw new UnexpectedError(spaceTrim(function (block) { return "\n Loop limit reached during detection of circular dependencies in `validatePipeline`\n\n ".concat(block(pipelineIdentification), "\n "); }));
1271
1402
  }
1272
1403
  var currentlyResovedTemplates = unresovedTemplates.filter(function (template) {
1273
1404
  return template.dependentParameterNames.every(function (name) { return resovedParameters.includes(name); });
@@ -1275,7 +1406,7 @@ function validatePipeline(pipeline) {
1275
1406
  if (currentlyResovedTemplates.length === 0) {
1276
1407
  throw new PipelineLogicError(
1277
1408
  // TODO: [🐎] DRY
1278
- 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
1409
+ 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
1279
1410
  .map(function (_a) {
1280
1411
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
1281
1412
  return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
@@ -1337,15 +1468,15 @@ var NotFoundError = /** @class */ (function (_super) {
1337
1468
  *
1338
1469
  * @public exported from `@promptbook/core`
1339
1470
  */
1340
- var ReferenceError$1 = /** @class */ (function (_super) {
1341
- __extends(ReferenceError, _super);
1342
- function ReferenceError(message) {
1471
+ var PipelineUrlError = /** @class */ (function (_super) {
1472
+ __extends(PipelineUrlError, _super);
1473
+ function PipelineUrlError(message) {
1343
1474
  var _this = _super.call(this, message) || this;
1344
- _this.name = 'ReferenceError';
1345
- Object.setPrototypeOf(_this, ReferenceError.prototype);
1475
+ _this.name = 'PipelineUrlError';
1476
+ Object.setPrototypeOf(_this, PipelineUrlError.prototype);
1346
1477
  return _this;
1347
1478
  }
1348
- return ReferenceError;
1479
+ return PipelineUrlError;
1349
1480
  }(Error));
1350
1481
 
1351
1482
  /**
@@ -1393,7 +1524,7 @@ function unpreparePipeline(pipeline) {
1393
1524
  delete promptTemplateUnprepared.preparedContent;
1394
1525
  return promptTemplateUnprepared;
1395
1526
  });
1396
- return __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] });
1527
+ return $asDeeplyFrozenSerializableJson('Unprepared PipelineJson', __assign(__assign({}, pipeline), { promptTemplates: promptTemplates, knowledgeSources: knowledgeSources, knowledgePieces: [], personas: personas, preparations: [] }));
1397
1528
  }
1398
1529
  /**
1399
1530
  * TODO: [🧿] Maybe do same process with same granularity and subfinctions as `preparePipeline`
@@ -1429,7 +1560,7 @@ var SimplePipelineCollection = /** @class */ (function () {
1429
1560
  var pipeline = pipelines_1_1.value;
1430
1561
  // TODO: [👠] DRY
1431
1562
  if (pipeline.pipelineUrl === undefined) {
1432
- 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 ")));
1563
+ 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 ")));
1433
1564
  }
1434
1565
  // Note: [🐨]
1435
1566
  validatePipeline(pipeline);
@@ -1441,7 +1572,7 @@ var SimplePipelineCollection = /** @class */ (function () {
1441
1572
  pipelineJsonToString(unpreparePipeline(pipeline)) !==
1442
1573
  pipelineJsonToString(unpreparePipeline(this.collection.get(pipeline.pipelineUrl)))) {
1443
1574
  var existing = this.collection.get(pipeline.pipelineUrl);
1444
- 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 ")));
1575
+ 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 ")));
1445
1576
  }
1446
1577
  // Note: [🧠] Overwrite existing pipeline with the same URL
1447
1578
  this.collection.set(pipeline.pipelineUrl, pipeline);
@@ -1471,9 +1602,9 @@ var SimplePipelineCollection = /** @class */ (function () {
1471
1602
  var pipeline = this.collection.get(url);
1472
1603
  if (!pipeline) {
1473
1604
  if (this.listPipelines().length === 0) {
1474
- throw new NotFoundError(spaceTrim$1("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
1605
+ throw new NotFoundError(spaceTrim("\n Pipeline with url \"".concat(url, "\" not found\n\n No pipelines available\n ")));
1475
1606
  }
1476
- 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()
1607
+ throw new NotFoundError(spaceTrim(function (block) { return "\n Pipeline with url \"".concat(url, "\" not found\n\n Available pipelines:\n ").concat(block(_this.listPipelines()
1477
1608
  .map(function (pipelineUrl) { return "- ".concat(pipelineUrl); })
1478
1609
  .join('\n')), "\n\n "); }));
1479
1610
  }
@@ -1886,9 +2017,89 @@ var PipelineExecutionError = /** @class */ (function (_super) {
1886
2017
  }(Error));
1887
2018
 
1888
2019
  /**
1889
- * Asserts that the execution of a promptnook is successful
2020
+ * This error indicates that the pipeline collection cannot be propperly loaded
1890
2021
  *
1891
- * @param executionResult - The partial result of the promptnook execution
2022
+ * @public exported from `@promptbook/core`
2023
+ */
2024
+ var CollectionError = /** @class */ (function (_super) {
2025
+ __extends(CollectionError, _super);
2026
+ function CollectionError(message) {
2027
+ var _this = _super.call(this, message) || this;
2028
+ _this.name = 'CollectionError';
2029
+ Object.setPrototypeOf(_this, CollectionError.prototype);
2030
+ return _this;
2031
+ }
2032
+ return CollectionError;
2033
+ }(Error));
2034
+
2035
+ /**
2036
+ * This error type indicates that some limit was reached
2037
+ *
2038
+ * @public exported from `@promptbook/core`
2039
+ */
2040
+ var LimitReachedError = /** @class */ (function (_super) {
2041
+ __extends(LimitReachedError, _super);
2042
+ function LimitReachedError(message) {
2043
+ var _this = _super.call(this, message) || this;
2044
+ _this.name = 'LimitReachedError';
2045
+ Object.setPrototypeOf(_this, LimitReachedError.prototype);
2046
+ return _this;
2047
+ }
2048
+ return LimitReachedError;
2049
+ }(Error));
2050
+
2051
+ /**
2052
+ * This error type indicates that some part of the code is not implemented yet
2053
+ *
2054
+ * @public exported from `@promptbook/core`
2055
+ */
2056
+ var NotYetImplementedError = /** @class */ (function (_super) {
2057
+ __extends(NotYetImplementedError, _super);
2058
+ function NotYetImplementedError(message) {
2059
+ 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;
2060
+ _this.name = 'NotYetImplementedError';
2061
+ Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
2062
+ return _this;
2063
+ }
2064
+ return NotYetImplementedError;
2065
+ }(Error));
2066
+
2067
+ /**
2068
+ * Index of all custom errors
2069
+ *
2070
+ * @public exported from `@promptbook/core`
2071
+ */
2072
+ var ERRORS = {
2073
+ CollectionError: CollectionError,
2074
+ EnvironmentMismatchError: EnvironmentMismatchError,
2075
+ LimitReachedError: LimitReachedError,
2076
+ NotFoundError: NotFoundError,
2077
+ NotYetImplementedError: NotYetImplementedError,
2078
+ ParsingError: ParsingError,
2079
+ PipelineExecutionError: PipelineExecutionError,
2080
+ PipelineLogicError: PipelineLogicError,
2081
+ PipelineUrlError: PipelineUrlError,
2082
+ UnexpectedError: UnexpectedError,
2083
+ // TODO: [🪑]> VersionMismatchError,
2084
+ };
2085
+
2086
+ /**
2087
+ * Deserializes the error object
2088
+ *
2089
+ * @public exported from `@promptbook/utils`
2090
+ */
2091
+ function deserializeError(error) {
2092
+ if (error.name === 'Error') {
2093
+ return new Error(error.message);
2094
+ }
2095
+ var CustomError = ERRORS[error.name];
2096
+ return new CustomError(error.message);
2097
+ }
2098
+
2099
+ /**
2100
+ * Asserts that the execution of a Promptbook is successful
2101
+ *
2102
+ * @param executionResult - The partial result of the Promptbook execution
1892
2103
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
1893
2104
  * @public exported from `@promptbook/core`
1894
2105
  */
@@ -1898,15 +2109,16 @@ function assertsExecutionSuccessful(executionResult) {
1898
2109
  return;
1899
2110
  }
1900
2111
  if (errors.length === 0) {
1901
- throw new PipelineExecutionError("Promptnook Execution failed because of unknown reason");
2112
+ throw new PipelineExecutionError("Promptbook Execution failed because of unknown reason");
1902
2113
  }
1903
2114
  else if (errors.length === 1) {
1904
- throw errors[0];
2115
+ throw deserializeError(errors[0]);
1905
2116
  }
1906
2117
  else {
1907
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Multiple errors occurred during promptnook execution\n\n ".concat(block(errors
1908
- .map(function (error, index) {
1909
- return spaceTrim$1(function (block) { return "\n Error ".concat(index + 1, ":\n ").concat(block(error.stack || error.message), "\n "); });
2118
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Multiple errors occurred during Promptbook execution\n\n ".concat(block(errors
2119
+ .map(function (_a, index) {
2120
+ var name = _a.name, stack = _a.stack, message = _a.message;
2121
+ return spaceTrim(function (block) { return "\n ".concat(name, " ").concat(index + 1, ":\n ").concat(block(stack || message), "\n "); });
1910
2122
  })
1911
2123
  .join('\n')), "\n "); }));
1912
2124
  }
@@ -1938,7 +2150,7 @@ function extractVariables(script) {
1938
2150
  var undefinedName = error.message.split(' ')[0];
1939
2151
  /*
1940
2152
  Note: Parsing the error
1941
- [ReferenceError: thing is not defined]
2153
+ [PipelineUrlError: thing is not defined]
1942
2154
  */
1943
2155
  if (!undefinedName) {
1944
2156
  throw error;
@@ -1956,7 +2168,7 @@ function extractVariables(script) {
1956
2168
  if (!(error instanceof Error)) {
1957
2169
  throw error;
1958
2170
  }
1959
- 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 "); }));
2171
+ throw new ParsingError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n "); }));
1960
2172
  }
1961
2173
  return variables;
1962
2174
  }
@@ -2043,6 +2255,23 @@ var ExpectError = /** @class */ (function (_super) {
2043
2255
  return ExpectError;
2044
2256
  }(Error));
2045
2257
 
2258
+ /**
2259
+ * Serializes an error into a [🚉] JSON-serializable object
2260
+ *
2261
+ * @public exported from `@promptbook/utils`
2262
+ */
2263
+ function serializeError(error) {
2264
+ var name = error.name, message = error.message, stack = error.stack;
2265
+ if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
2266
+ 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 "); }));
2267
+ }
2268
+ return {
2269
+ name: name,
2270
+ message: message,
2271
+ stack: stack,
2272
+ };
2273
+ }
2274
+
2046
2275
  /**
2047
2276
  * Function isValidJsonString will tell you if the string is valid JSON or not
2048
2277
  *
@@ -2282,7 +2511,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
2282
2511
  // 1) OpenAI throw PipelineExecutionError: Parameter {knowledge} is not defined
2283
2512
  // 2) AnthropicClaude throw PipelineExecutionError: Parameter {knowledge} is not defined
2284
2513
  // 3) ...
2285
- spaceTrim(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2514
+ spaceTrim$1(function (block) { return "\n All execution tools failed:\n\n ".concat(block(errors
2286
2515
  .map(function (error, i) { return "".concat(i + 1, ") **").concat(error.name || 'Error', ":** ").concat(error.message); })
2287
2516
  .join('\n')), "\n\n "); }));
2288
2517
  }
@@ -2290,7 +2519,7 @@ var MultipleLlmExecutionTools = /** @class */ (function () {
2290
2519
  throw new PipelineExecutionError("You have not provided any `LlmExecutionTools`");
2291
2520
  }
2292
2521
  else {
2293
- 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
2522
+ 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
2294
2523
  .map(function (tools) { return "- ".concat(tools.title, " ").concat(tools.description || ''); })
2295
2524
  .join('\n')), "\n\n "); }));
2296
2525
  }
@@ -2327,7 +2556,7 @@ function joinLlmExecutionTools() {
2327
2556
  llmExecutionTools[_i] = arguments[_i];
2328
2557
  }
2329
2558
  if (llmExecutionTools.length === 0) {
2330
- 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 ");
2559
+ 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 ");
2331
2560
  // TODO: [🟥] Detect browser / node and make it colorfull
2332
2561
  console.warn(warningMessage);
2333
2562
  /*
@@ -2424,22 +2653,6 @@ function TODO_USE() {
2424
2653
  }
2425
2654
  }
2426
2655
 
2427
- /**
2428
- * This error type indicates that some limit was reached
2429
- *
2430
- * @public exported from `@promptbook/core`
2431
- */
2432
- var LimitReachedError = /** @class */ (function (_super) {
2433
- __extends(LimitReachedError, _super);
2434
- function LimitReachedError(message) {
2435
- var _this = _super.call(this, message) || this;
2436
- _this.name = 'LimitReachedError';
2437
- Object.setPrototypeOf(_this, LimitReachedError.prototype);
2438
- return _this;
2439
- }
2440
- return LimitReachedError;
2441
- }(Error));
2442
-
2443
2656
  /**
2444
2657
  * Replaces parameters in template with values from parameters object
2445
2658
  *
@@ -2739,7 +2952,7 @@ function createPipelineExecutor(options) {
2739
2952
  preparedPipeline = pipeline;
2740
2953
  }
2741
2954
  else if (isNotPreparedWarningSupressed !== true) {
2742
- 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 ")));
2955
+ 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 ")));
2743
2956
  }
2744
2957
  var pipelineExecutor = function (inputParameters, onProgress) { return __awaiter(_this, void 0, void 0, function () {
2745
2958
  // TODO: !!! Extract to separate functions and files - ALL FUNCTIONS BELOW
@@ -2825,7 +3038,6 @@ function createPipelineExecutor(options) {
2825
3038
  return __awaiter(this, void 0, void 0, function () {
2826
3039
  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;
2827
3040
  var e_7, _p, e_4, _q, e_6, _r, e_5, _s, _t;
2828
- var _this = this;
2829
3041
  return __generator(this, function (_u) {
2830
3042
  switch (_u.label) {
2831
3043
  case 0:
@@ -2850,7 +3062,7 @@ function createPipelineExecutor(options) {
2850
3062
  usedParameterNames = extractParameterNamesFromPromptTemplate(currentTemplate);
2851
3063
  dependentParameterNames = new Set(currentTemplate.dependentParameterNames);
2852
3064
  if (union(difference(usedParameterNames, dependentParameterNames), difference(dependentParameterNames, usedParameterNames)).size !== 0) {
2853
- 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 ")));
3065
+ 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 ")));
2854
3066
  }
2855
3067
  _b = (_a = Object).freeze;
2856
3068
  _c = [{}];
@@ -2875,7 +3087,7 @@ function createPipelineExecutor(options) {
2875
3087
  else if (!definedParameterNames.has(parameterName) && usedParameterNames.has(parameterName)) {
2876
3088
  // Houston, we have a problem
2877
3089
  // Note: Checking part is also done in `validatePipeline`, but it’s good to doublecheck
2878
- 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 ")));
3090
+ 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 ")));
2879
3091
  }
2880
3092
  }
2881
3093
  }
@@ -2946,71 +3158,8 @@ function createPipelineExecutor(options) {
2946
3158
  return name === currentTemplate.personaName;
2947
3159
  }) || {})), currentTemplate.expectations),
2948
3160
  expectFormat: currentTemplate.expectFormat,
2949
- postprocessing: (currentTemplate.postprocessingFunctionNames || []).map(function (functionName) { return function (result) { return __awaiter(_this, void 0, void 0, function () {
2950
- var errors, _a, _b, scriptTools, error_5, e_8_1;
2951
- var e_8, _c;
2952
- return __generator(this, function (_d) {
2953
- switch (_d.label) {
2954
- case 0:
2955
- errors = [];
2956
- _d.label = 1;
2957
- case 1:
2958
- _d.trys.push([1, 8, 9, 10]);
2959
- _a = __values(arrayableToArray(tools.script)), _b = _a.next();
2960
- _d.label = 2;
2961
- case 2:
2962
- if (!!_b.done) return [3 /*break*/, 7];
2963
- scriptTools = _b.value;
2964
- _d.label = 3;
2965
- case 3:
2966
- _d.trys.push([3, 5, , 6]);
2967
- return [4 /*yield*/, scriptTools.execute({
2968
- scriptLanguage: "javascript" /* <- TODO: Try it in each languages; In future allow postprocessing with arbitrary combination of languages to combine */,
2969
- script: "".concat(functionName, "(result)"),
2970
- parameters: {
2971
- result: result || '',
2972
- // Note: No ...parametersForTemplate, because working with result only
2973
- },
2974
- })];
2975
- case 4: return [2 /*return*/, _d.sent()];
2976
- case 5:
2977
- error_5 = _d.sent();
2978
- if (!(error_5 instanceof Error)) {
2979
- throw error_5;
2980
- }
2981
- if (error_5 instanceof UnexpectedError) {
2982
- throw error_5;
2983
- }
2984
- errors.push(error_5);
2985
- return [3 /*break*/, 6];
2986
- case 6:
2987
- _b = _a.next();
2988
- return [3 /*break*/, 2];
2989
- case 7: return [3 /*break*/, 10];
2990
- case 8:
2991
- e_8_1 = _d.sent();
2992
- e_8 = { error: e_8_1 };
2993
- return [3 /*break*/, 10];
2994
- case 9:
2995
- try {
2996
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
2997
- }
2998
- finally { if (e_8) throw e_8.error; }
2999
- return [7 /*endfinally*/];
3000
- case 10:
3001
- if (errors.length === 0) {
3002
- throw new PipelineExecutionError('Postprocessing in LlmExecutionTools failed because no ScriptExecutionTools were provided');
3003
- }
3004
- else if (errors.length === 1) {
3005
- throw errors[0];
3006
- }
3007
- else {
3008
- 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 "); }));
3009
- }
3010
- }
3011
- });
3012
- }); }; }),
3013
- };
3161
+ postprocessingFunctionNames: currentTemplate.postprocessingFunctionNames,
3162
+ }; // <- TODO: Not very good type guard
3014
3163
  _g = currentTemplate.modelRequirements.modelVariant;
3015
3164
  switch (_g) {
3016
3165
  case 'CHAT': return [3 /*break*/, 8];
@@ -3099,7 +3248,7 @@ function createPipelineExecutor(options) {
3099
3248
  throw scriptPipelineExecutionErrors[0];
3100
3249
  }
3101
3250
  else {
3102
- throw new PipelineExecutionError(spaceTrim$1(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
3251
+ throw new PipelineExecutionError(spaceTrim(function (block) { return "\n Script execution failed ".concat(scriptPipelineExecutionErrors.length, " times\n\n ").concat(block(scriptPipelineExecutionErrors
3103
3252
  .map(function (error) { return '- ' + error.message; })
3104
3253
  .join('\n\n')), "\n "); }));
3105
3254
  }
@@ -3235,13 +3384,13 @@ function createPipelineExecutor(options) {
3235
3384
  executionReport.promptExecutions.push({
3236
3385
  prompt: __assign({}, prompt),
3237
3386
  result: result || undefined,
3238
- error: expectError || undefined,
3387
+ error: expectError === null ? undefined : serializeError(expectError),
3239
3388
  });
3240
3389
  }
3241
3390
  return [7 /*endfinally*/];
3242
3391
  case 50:
3243
3392
  if (expectError !== null && attempt === maxAttempts - 1) {
3244
- 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 "); }));
3393
+ 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 "); }));
3245
3394
  }
3246
3395
  _u.label = 51;
3247
3396
  case 51:
@@ -3270,7 +3419,7 @@ function createPipelineExecutor(options) {
3270
3419
  });
3271
3420
  }
3272
3421
  function filterJustOutputParameters() {
3273
- var e_9, _a;
3422
+ var e_8, _a;
3274
3423
  var outputParameters = {};
3275
3424
  try {
3276
3425
  // Note: Filter ONLY output parameters
@@ -3287,12 +3436,12 @@ function createPipelineExecutor(options) {
3287
3436
  outputParameters[parameter.name] = parametersToPass[parameter.name] || '';
3288
3437
  }
3289
3438
  }
3290
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
3439
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
3291
3440
  finally {
3292
3441
  try {
3293
3442
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3294
3443
  }
3295
- finally { if (e_9) throw e_9.error; }
3444
+ finally { if (e_8) throw e_8.error; }
3296
3445
  }
3297
3446
  return outputParameters;
3298
3447
  }
@@ -3329,11 +3478,11 @@ function createPipelineExecutor(options) {
3329
3478
  })), _b = _a.next(); !_b.done; _b = _a.next()) {
3330
3479
  parameter = _b.value;
3331
3480
  if (inputParameters[parameter.name] === undefined) {
3332
- return [2 /*return*/, deepFreezeWithSameType({
3481
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with missing parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
3333
3482
  isSuccessful: false,
3334
3483
  errors: __spreadArray([
3335
3484
  new PipelineExecutionError("Parameter {".concat(parameter.name, "} is required as an input parameter"))
3336
- ], __read(errors), false),
3485
+ ], __read(errors), false).map(serializeError),
3337
3486
  warnings: [],
3338
3487
  executionReport: executionReport,
3339
3488
  outputParameters: {},
@@ -3359,12 +3508,12 @@ function createPipelineExecutor(options) {
3359
3508
  warnings.push(new PipelineExecutionError("Extra parameter {".concat(parameterName, "} is being passed which is not part of the pipeline.")));
3360
3509
  }
3361
3510
  else if (parameter.isInput === false) {
3362
- return { value: deepFreezeWithSameType({
3511
+ return { value: $asDeeplyFrozenSerializableJson("Unuccessful PipelineExecutorResult (with extra parameter {".concat(parameter.name, "}) PipelineExecutorResult"), {
3363
3512
  isSuccessful: false,
3364
3513
  errors: __spreadArray([
3365
3514
  new PipelineExecutionError("Parameter {".concat(parameter.name, "} is passed as input parameter but it is not input"))
3366
- ], __read(errors), false),
3367
- warnings: warnings,
3515
+ ], __read(errors), false).map(serializeError),
3516
+ warnings: warnings.map(serializeError),
3368
3517
  executionReport: executionReport,
3369
3518
  outputParameters: {},
3370
3519
  usage: ZERO_USAGE,
@@ -3421,7 +3570,7 @@ function createPipelineExecutor(options) {
3421
3570
  if (!(!currentTemplate && resolving_1.length === 0)) return [3 /*break*/, 1];
3422
3571
  throw new UnexpectedError(
3423
3572
  // TODO: [🐎] DRY
3424
- spaceTrim$1(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
3573
+ spaceTrim(function (block) { return "\n Can not resolve some parameters:\n\n Can not resolve:\n ".concat(block(unresovedTemplates_1
3425
3574
  .map(function (_a) {
3426
3575
  var resultingParameterName = _a.resultingParameterName, dependentParameterNames = _a.dependentParameterNames;
3427
3576
  return "- Parameter {".concat(resultingParameterName, "} which depends on ").concat(dependentParameterNames
@@ -3471,10 +3620,10 @@ function createPipelineExecutor(options) {
3471
3620
  return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
3472
3621
  })), false));
3473
3622
  outputParameters_1 = filterJustOutputParameters();
3474
- return [2 /*return*/, deepFreezeWithSameType({
3623
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Unuccessful PipelineExecutorResult (with misc errors) PipelineExecutorResult', {
3475
3624
  isSuccessful: false,
3476
- errors: __spreadArray([error_1], __read(errors), false),
3477
- warnings: warnings,
3625
+ errors: __spreadArray([error_1], __read(errors), false).map(serializeError),
3626
+ warnings: warnings.map(serializeError),
3478
3627
  usage: usage_1,
3479
3628
  executionReport: executionReport,
3480
3629
  outputParameters: outputParameters_1,
@@ -3486,10 +3635,10 @@ function createPipelineExecutor(options) {
3486
3635
  return (result === null || result === void 0 ? void 0 : result.usage) || ZERO_USAGE;
3487
3636
  })), false));
3488
3637
  outputParameters = filterJustOutputParameters();
3489
- return [2 /*return*/, deepFreezeWithSameType({
3638
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Successful PipelineExecutorResult', {
3490
3639
  isSuccessful: true,
3491
- errors: errors,
3492
- warnings: warnings,
3640
+ errors: errors.map(serializeError),
3641
+ warnings: warnings.map(serializeError),
3493
3642
  usage: usage,
3494
3643
  executionReport: executionReport,
3495
3644
  outputParameters: outputParameters,
@@ -3575,8 +3724,8 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
3575
3724
  switch (_c.label) {
3576
3725
  case 0:
3577
3726
  name = "piece-".concat(i);
3578
- title = spaceTrim(knowledgeTextPiece.substring(0, 100));
3579
- knowledgePieceContent = spaceTrim(knowledgeTextPiece);
3727
+ title = spaceTrim$1(knowledgeTextPiece.substring(0, 100));
3728
+ knowledgePieceContent = spaceTrim$1(knowledgeTextPiece);
3580
3729
  keywords = [];
3581
3730
  index = [];
3582
3731
  _c.label = 1;
@@ -3586,7 +3735,7 @@ function prepareKnowledgeFromMarkdown(knowledgeContent /* <- TODO: [🖖] (?mayb
3586
3735
  case 2:
3587
3736
  titleResult = _c.sent();
3588
3737
  _a = titleResult.outputParameters.title, titleRaw = _a === void 0 ? 'Untitled' : _a;
3589
- title = spaceTrim(titleRaw) /* <- TODO: Maybe do in pipeline */;
3738
+ title = spaceTrim$1(titleRaw) /* <- TODO: Maybe do in pipeline */;
3590
3739
  name = titleToName(title);
3591
3740
  return [4 /*yield*/, prepareKeywordsExecutor({ knowledgePieceContent: knowledgePieceContent })];
3592
3741
  case 3:
@@ -3918,7 +4067,7 @@ function prepareTemplates(pipeline, options) {
3918
4067
  dependentParameterNames = template.dependentParameterNames;
3919
4068
  preparedContent = undefined;
3920
4069
  if (knowledgePiecesCount > 0 && !dependentParameterNames.includes('knowledge')) {
3921
- preparedContent = spaceTrim$1("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
4070
+ preparedContent = spaceTrim("\n {content}\n\n ## Knowledge\n\n {knowledge}\n ");
3922
4071
  // <- TODO: [🧠][🧻] Cutomize shape/language/formatting of the addition to the prompt
3923
4072
  dependentParameterNames = __spreadArray(__spreadArray([], __read(dependentParameterNames), false), [
3924
4073
  'knowledge',
@@ -3959,7 +4108,7 @@ function preparePipeline(pipeline, options) {
3959
4108
  return __awaiter(this, void 0, void 0, function () {
3960
4109
  var llmTools, _a, maxParallelCount, _b, isVerbose, parameters, promptTemplates,
3961
4110
  /*
3962
- <- TODO: [🧠][0] `promptbookVersion` */
4111
+ <- TODO: [🧠][🪑] `promptbookVersion` */
3963
4112
  knowledgeSources /*
3964
4113
  <- TODO: [🧊] `knowledgePieces` */, personas /*
3965
4114
  <- TODO: [🧊] `preparations` */, llmToolsWithUsage, currentPreparation, preparations, preparedPersonas, knowledgeSourcesPrepared, partialknowledgePiecesPrepared, knowledgePiecesPrepared, promptTemplatesPrepared /* TODO: parameters: parametersPrepared*/;
@@ -4029,7 +4178,7 @@ function preparePipeline(pipeline, options) {
4029
4178
  // ----- /Templates preparation -----
4030
4179
  // Note: Count total usage
4031
4180
  currentPreparation.usage = llmToolsWithUsage.getTotalUsage();
4032
- return [2 /*return*/, __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations })];
4181
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('Prepared PipelineJson', __assign(__assign({}, clonePipeline(pipeline)), { promptTemplates: promptTemplatesPrepared, knowledgeSources: knowledgeSourcesPrepared, knowledgePieces: knowledgePiecesPrepared, personas: preparedPersonas, preparations: preparations }))];
4033
4182
  }
4034
4183
  });
4035
4184
  });
@@ -4105,7 +4254,7 @@ var knowledgeCommandParser = {
4105
4254
  */
4106
4255
  parse: function (input) {
4107
4256
  var args = input.args;
4108
- var sourceContent = spaceTrim(args[0] || '');
4257
+ var sourceContent = spaceTrim$1(args[0] || '');
4109
4258
  if (sourceContent === '') {
4110
4259
  throw new ParsingError("Source is not defined");
4111
4260
  }
@@ -4221,8 +4370,8 @@ var personaCommandParser = {
4221
4370
  persona.description = personaDescription;
4222
4371
  return;
4223
4372
  }
4224
- 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 ")));
4225
- persona.description += spaceTrim('\n\n' + personaDescription);
4373
+ 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 ")));
4374
+ persona.description += spaceTrim$1('\n\n' + personaDescription);
4226
4375
  },
4227
4376
  };
4228
4377
 
@@ -4409,7 +4558,7 @@ var blockCommandParser = {
4409
4558
  normalized = normalized.split('EXAMPLE').join('SAMPLE');
4410
4559
  var blockTypes = BlockTypes.filter(function (blockType) { return normalized.includes(blockType); });
4411
4560
  if (blockTypes.length !== 1) {
4412
- 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 "); }));
4561
+ 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 "); }));
4413
4562
  }
4414
4563
  var blockType = blockTypes[0];
4415
4564
  return {
@@ -4516,7 +4665,7 @@ var expectCommandParser = {
4516
4665
  /**
4517
4666
  * Description of the EXPECT command
4518
4667
  */
4519
- 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 "),
4668
+ 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 "),
4520
4669
  /**
4521
4670
  * Link to discussion
4522
4671
  */
@@ -4609,7 +4758,7 @@ var expectCommandParser = {
4609
4758
  if (!(error instanceof Error)) {
4610
4759
  throw error;
4611
4760
  }
4612
- throw new ParsingError(spaceTrim(function (block) {
4761
+ throw new ParsingError(spaceTrim$1(function (block) {
4613
4762
  return "\n Invalid EXPECT command\n ".concat(block(error.message), ":\n ");
4614
4763
  }));
4615
4764
  }
@@ -4728,7 +4877,7 @@ var modelCommandParser = {
4728
4877
  // <- Note: [🤖]
4729
4878
  }
4730
4879
  else {
4731
- 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 "); }));
4880
+ 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 "); }));
4732
4881
  }
4733
4882
  }
4734
4883
  if (normalized.startsWith('MODEL_NAME')) {
@@ -4739,7 +4888,7 @@ var modelCommandParser = {
4739
4888
  };
4740
4889
  }
4741
4890
  else {
4742
- 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 "); }));
4891
+ 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 "); }));
4743
4892
  }
4744
4893
  },
4745
4894
  };
@@ -5198,7 +5347,7 @@ function parseCommand(raw, usagePlace) {
5198
5347
  .map(removeMarkdownFormatting)
5199
5348
  .map(function (item) { return item.trim(); });
5200
5349
  if (items.length === 0 || items[0] === '') {
5201
- throw new ParsingError(spaceTrim$1(function (block) {
5350
+ throw new ParsingError(spaceTrim(function (block) {
5202
5351
  return "\n Malformed command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5203
5352
  }));
5204
5353
  }
@@ -5225,7 +5374,7 @@ function parseCommand(raw, usagePlace) {
5225
5374
  return command;
5226
5375
  }
5227
5376
  }
5228
- throw new ParsingError(spaceTrim$1(function (block) {
5377
+ throw new ParsingError(spaceTrim(function (block) {
5229
5378
  return "\n Malformed or unknown command:\n\n - ".concat(raw, "\n\n Supported commands are:\n ").concat(block(getSupportedCommandsMessage()), "\n\n ");
5230
5379
  }));
5231
5380
  }
@@ -5258,7 +5407,7 @@ function parseCommandVariant(input) {
5258
5407
  if (!(error instanceof ParsingError)) {
5259
5408
  throw error;
5260
5409
  }
5261
- throw new ParsingError(spaceTrim$1(function (block) {
5410
+ throw new ParsingError(spaceTrim(function (block) {
5262
5411
  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 ");
5263
5412
  }));
5264
5413
  }
@@ -5285,22 +5434,6 @@ function parseCommandVariant(input) {
5285
5434
  return null;
5286
5435
  }
5287
5436
 
5288
- /**
5289
- * This error type indicates that some part of the code is not implemented yet
5290
- *
5291
- * @public exported from `@promptbook/core`
5292
- */
5293
- var NotYetImplementedError = /** @class */ (function (_super) {
5294
- __extends(NotYetImplementedError, _super);
5295
- function NotYetImplementedError(message) {
5296
- 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;
5297
- _this.name = 'NotYetImplementedError';
5298
- Object.setPrototypeOf(_this, NotYetImplementedError.prototype);
5299
- return _this;
5300
- }
5301
- return NotYetImplementedError;
5302
- }(Error));
5303
-
5304
5437
  /**
5305
5438
  * Supported script languages
5306
5439
  *
@@ -5440,7 +5573,7 @@ function extractAllBlocksFromMarkdown(markdown) {
5440
5573
  function extractOneBlockFromMarkdown(markdown) {
5441
5574
  var codeBlocks = extractAllBlocksFromMarkdown(markdown);
5442
5575
  if (codeBlocks.length !== 1) {
5443
- 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 "); }));
5576
+ 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 "); }));
5444
5577
  }
5445
5578
  return codeBlocks[0];
5446
5579
  }
@@ -5461,7 +5594,7 @@ function parseMarkdownSection(value) {
5461
5594
  }
5462
5595
  var title = lines[0].replace(/^#+\s*/, '');
5463
5596
  var level = (_b = (_a = lines[0].match(/^#+/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
5464
- var content = spaceTrim(lines.slice(1).join('\n'));
5597
+ var content = spaceTrim$1(lines.slice(1).join('\n'));
5465
5598
  if (level < 1 || level > 6) {
5466
5599
  throw new ParsingError('Markdown section must have heading level between 1 and 6');
5467
5600
  }
@@ -5489,7 +5622,7 @@ function splitMarkdownIntoSections(markdown) {
5489
5622
  if (buffer.length === 0) {
5490
5623
  return;
5491
5624
  }
5492
- var section = spaceTrim(buffer.join('\n'));
5625
+ var section = spaceTrim$1(buffer.join('\n'));
5493
5626
  if (section === '') {
5494
5627
  return;
5495
5628
  }
@@ -5585,7 +5718,7 @@ function flattenMarkdown(markdown) {
5585
5718
  }
5586
5719
  finally { if (e_1) throw e_1.error; }
5587
5720
  }
5588
- return spaceTrim(flattenedMarkdown);
5721
+ return spaceTrim$1(flattenedMarkdown);
5589
5722
  }
5590
5723
  /**
5591
5724
  * TODO: [🏛] This can be part of markdown builder
@@ -5603,7 +5736,7 @@ function flattenMarkdown(markdown) {
5603
5736
  * @public exported from `@promptbook/markdown-utils`
5604
5737
  */
5605
5738
  function removeContentComments(content) {
5606
- return spaceTrim$1(content.replace(/<!--(.*?)-->/gs, ''));
5739
+ return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
5607
5740
  }
5608
5741
 
5609
5742
  /**
@@ -5644,13 +5777,13 @@ function pipelineStringToJsonSync(pipelineString) {
5644
5777
  pipelineString = pipelineString.replaceAll(/`->\s+\{(?<parameterName>[a-z0-9_]+)\}`/gi, '-> {$<parameterName>}');
5645
5778
  var _c = __read(splitMarkdownIntoSections(pipelineString).map(parseMarkdownSection)), pipelineHead = _c[0], pipelineSections = _c.slice(1); /* <- Note: [🥞] */
5646
5779
  if (pipelineHead === undefined) {
5647
- throw new UnexpectedError(spaceTrim$1("\n Pipeline head is not defined\n\n This should never happen, because the pipeline already flattened\n "));
5780
+ throw new UnexpectedError(spaceTrim("\n Pipeline head is not defined\n\n This should never happen, because the pipeline already flattened\n "));
5648
5781
  }
5649
5782
  if (pipelineHead.level !== 1) {
5650
- throw new UnexpectedError(spaceTrim$1("\n Pipeline head is not h1\n\n This should never happen, because the pipeline already flattened\n "));
5783
+ throw new UnexpectedError(spaceTrim("\n Pipeline head is not h1\n\n This should never happen, because the pipeline already flattened\n "));
5651
5784
  }
5652
5785
  if (!pipelineSections.every(function (section) { return section.level === 2; })) {
5653
- throw new UnexpectedError(spaceTrim$1("\n Not every pipeline section is h2\n\n This should never happen, because the pipeline already flattened\n "));
5786
+ throw new UnexpectedError(spaceTrim("\n Not every pipeline section is h2\n\n This should never happen, because the pipeline already flattened\n "));
5654
5787
  }
5655
5788
  // =============================================================
5656
5789
  ///Note: 2️⃣ Function for defining parameters
@@ -5664,7 +5797,7 @@ function pipelineStringToJsonSync(pipelineString) {
5664
5797
  existingParameter.description &&
5665
5798
  existingParameter.description !== parameterDescription &&
5666
5799
  parameterDescription) {
5667
- 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 "); }));
5800
+ 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 "); }));
5668
5801
  }
5669
5802
  if (existingParameter) {
5670
5803
  if (parameterDescription) {
@@ -5690,7 +5823,7 @@ function pipelineStringToJsonSync(pipelineString) {
5690
5823
  description = description.split(/^>.*$/gm).join('');
5691
5824
  //Note: Remove lists and return statement - TODO: [🎾] Make util (exported from `@promptbool/utils`)
5692
5825
  description = description.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
5693
- description = spaceTrim$1(description);
5826
+ description = spaceTrim(description);
5694
5827
  if (description === '') {
5695
5828
  description = undefined;
5696
5829
  }
@@ -5761,7 +5894,7 @@ function pipelineStringToJsonSync(pipelineString) {
5761
5894
  if (resultingParameterName !== null) {
5762
5895
  return resultingParameterName;
5763
5896
  }
5764
- throw new ParsingError(spaceTrim$1(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
5897
+ throw new ParsingError(spaceTrim(function (block) { return "\n Template section must end with -> {parameterName}\n\n Invalid section:\n ".concat(block(
5765
5898
  // TODO: Show code of invalid sections each time + DRY
5766
5899
  section.content
5767
5900
  .split('\n')
@@ -5776,7 +5909,7 @@ function pipelineStringToJsonSync(pipelineString) {
5776
5909
  description_1 = description_1.split(/^>.*$/gm).join('');
5777
5910
  //Note: Remove lists and return statement - TODO: [🎾]
5778
5911
  description_1 = description_1.split(/^(?:(?:-)|(?:\d\))|(?:`?->))\s+.*$/gm).join('');
5779
- description_1 = spaceTrim$1(description_1);
5912
+ description_1 = spaceTrim(description_1);
5780
5913
  if (description_1 === '') {
5781
5914
  description_1 = undefined;
5782
5915
  }
@@ -5860,7 +5993,7 @@ function pipelineStringToJsonSync(pipelineString) {
5860
5993
  break;
5861
5994
  case 'EXPECT_FORMAT':
5862
5995
  if (templateJson.expectFormat !== undefined && command.format !== templateJson.expectFormat) {
5863
- 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 ")));
5996
+ 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 ")));
5864
5997
  }
5865
5998
  templateJson.expectFormat = command.format;
5866
5999
  break;
@@ -5917,7 +6050,7 @@ function pipelineStringToJsonSync(pipelineString) {
5917
6050
  throw new ParsingError('You must specify the language of the script in the prompt template');
5918
6051
  }
5919
6052
  if (!SUPPORTED_SCRIPT_LANGUAGES.includes(language)) {
5920
- 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 "); }));
6053
+ 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 "); }));
5921
6054
  }
5922
6055
  templateJson.contentLanguage = language;
5923
6056
  }
@@ -5992,7 +6125,7 @@ function pipelineStringToJsonSync(pipelineString) {
5992
6125
  }
5993
6126
  });
5994
6127
  // =============================================================
5995
- return pipelineJson;
6128
+ return $asDeeplyFrozenSerializableJson('pipelineJson', pipelineJson);
5996
6129
  }
5997
6130
  /**
5998
6131
  * TODO: !!!! Warn if used only sync version
@@ -6036,7 +6169,9 @@ function pipelineStringToJson(pipelineString, options) {
6036
6169
  case 1:
6037
6170
  pipelineJson = _a.sent();
6038
6171
  _a.label = 2;
6039
- case 2: return [2 /*return*/, pipelineJson];
6172
+ case 2:
6173
+ // Note: No need to use `$asDeeplyFrozenSerializableJson` because `pipelineStringToJsonSync` and `preparePipeline` already do that
6174
+ return [2 /*return*/, pipelineJson];
6040
6175
  }
6041
6176
  });
6042
6177
  });
@@ -6047,22 +6182,6 @@ function pipelineStringToJson(pipelineString, options) {
6047
6182
  * TODO: [🧠] Should be in generated JSON file GENERATOR_WARNING
6048
6183
  */
6049
6184
 
6050
- /**
6051
- * This error indicates that the pipeline collection cannot be propperly loaded
6052
- *
6053
- * @public exported from `@promptbook/core`
6054
- */
6055
- var CollectionError = /** @class */ (function (_super) {
6056
- __extends(CollectionError, _super);
6057
- function CollectionError(message) {
6058
- var _this = _super.call(this, message) || this;
6059
- _this.name = 'CollectionError';
6060
- Object.setPrototypeOf(_this, CollectionError.prototype);
6061
- return _this;
6062
- }
6063
- return CollectionError;
6064
- }(Error));
6065
-
6066
6185
  /**
6067
6186
  * Checks if the file exists
6068
6187
  *
@@ -6419,7 +6538,7 @@ function createCollectionFromDirectory(path, options) {
6419
6538
  }
6420
6539
  else {
6421
6540
  existing = collection.get(pipeline.pipelineUrl);
6422
- 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 ")));
6541
+ 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 ")));
6423
6542
  }
6424
6543
  }
6425
6544
  }
@@ -6429,7 +6548,7 @@ function createCollectionFromDirectory(path, options) {
6429
6548
  if (!(error_1 instanceof Error)) {
6430
6549
  throw error_1;
6431
6550
  }
6432
- 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 "); });
6551
+ 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 "); });
6433
6552
  if (isCrashedOnError) {
6434
6553
  throw new CollectionError(wrappedErrorMessage);
6435
6554
  }
@@ -6485,6 +6604,39 @@ function createCollectionFromDirectory(path, options) {
6485
6604
  * TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
6486
6605
  */
6487
6606
 
6607
+ /**
6608
+ * Tests if the value is [🚉] serializable as JSON
6609
+ *
6610
+ * - Almost all primitives are serializable BUT:
6611
+ * - `undefined` is not serializable
6612
+ * - `NaN` is not serializable
6613
+ * - Objects and arrays are serializable if all their properties are serializable
6614
+ * - Functions are not serializable
6615
+ * - Circular references are not serializable
6616
+ * - `Date` objects are not serializable
6617
+ * - `Map` and `Set` objects are not serializable
6618
+ * - `RegExp` objects are not serializable
6619
+ * - `Error` objects are not serializable
6620
+ * - `Symbol` objects are not serializable
6621
+ * - And much more...
6622
+ *
6623
+ *
6624
+ * @public exported from `@promptbook/utils`
6625
+ */
6626
+ function isSerializableAsJson(value) {
6627
+ try {
6628
+ checkSerializableAsJson('', value);
6629
+ return true;
6630
+ }
6631
+ catch (error) {
6632
+ return false;
6633
+ }
6634
+ }
6635
+ /**
6636
+ * TODO: [🧠] !!! In-memory cache of same values to prevent multiple checks
6637
+ * TODO: [🧠][💺] Can be done this on type-level?
6638
+ */
6639
+
6488
6640
  /**
6489
6641
  * Stringify the PipelineJson with proper formatting
6490
6642
  *
@@ -6494,6 +6646,9 @@ function createCollectionFromDirectory(path, options) {
6494
6646
  * @public exported from `@promptbook/core`
6495
6647
  */
6496
6648
  function stringifyPipelineJson(pipeline) {
6649
+ if (!isSerializableAsJson(pipeline)) {
6650
+ 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 "));
6651
+ }
6497
6652
  var pipelineJsonStringified = JSON.stringify(pipeline, null, 4);
6498
6653
  for (var i = 0; i < LOOP_LIMIT; i++) {
6499
6654
  pipelineJsonStringified = pipelineJsonStringified.replace(/(-?0\.\d+),[\n\s]+(-?0\.\d+)/gms, "$1".concat(REPLACING_NONCE, "$2"));
@@ -6542,7 +6697,7 @@ function usageToHuman(usage) {
6542
6697
  };
6543
6698
  report += '\n' + "- Cost ".concat(uncertainNumberToHuman(usage.price), " USD");
6544
6699
  report += '\n' + "- Saved ".concat(uncertainNumberToHuman(usageToWorktime(usage)), " hours of human time");
6545
- return spaceTrim(report);
6700
+ return spaceTrim$1(report);
6546
6701
  }
6547
6702
  /**
6548
6703
  * TODO: Use "$1" not "1 USD"
@@ -6619,6 +6774,9 @@ var FilesStorage = /** @class */ (function () {
6619
6774
  switch (_a.label) {
6620
6775
  case 0:
6621
6776
  filename = this.getFilenameForKey(key);
6777
+ if (!isSerializableAsJson(value)) {
6778
+ throw new UnexpectedError("The \"".concat(key, "\" you want to store in JSON file is not serializable as JSON"));
6779
+ }
6622
6780
  fileContent = stringifyPipelineJson(value);
6623
6781
  return [4 /*yield*/, mkdir(dirname(filename), { recursive: true })];
6624
6782
  case 1:
@@ -6663,14 +6821,11 @@ var FilesStorage = /** @class */ (function () {
6663
6821
  *
6664
6822
  * Note: `$` is used to indicate that this function is not a pure function - it access global scope
6665
6823
  *
6666
- * @public exported from `@promptbook/utils`
6824
+ * @private internal function of `$Register`
6667
6825
  */
6668
6826
  function $getGlobalScope() {
6669
6827
  return Function('return this')();
6670
6828
  }
6671
- /***
6672
- * TODO: !!!!! Make private and promptbook registry from this
6673
- */
6674
6829
 
6675
6830
  /**
6676
6831
  * Register is @@@
@@ -6795,7 +6950,7 @@ function $registeredLlmToolsMessage() {
6795
6950
  });
6796
6951
  return __assign(__assign({}, metadata), { isMetadataAviailable: isMetadataAviailable, isInstalled: isInstalled });
6797
6952
  });
6798
- return spaceTrim(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
6953
+ return spaceTrim$1(function (block) { return "\n Available LLM providers are:\n ".concat(block(metadata
6799
6954
  .map(function (_a, i) {
6800
6955
  var packageName = _a.packageName, className = _a.className, isMetadataAviailable = _a.isMetadataAviailable, isInstalled = _a.isInstalled;
6801
6956
  var more;
@@ -6843,7 +6998,7 @@ function createLlmToolsFromConfiguration(configuration, options) {
6843
6998
  return llmConfiguration.packageName === packageName && llmConfiguration.className === className;
6844
6999
  });
6845
7000
  if (registeredItem === undefined) {
6846
- 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 "); }));
7001
+ 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 "); }));
6847
7002
  }
6848
7003
  return registeredItem(__assign({ isVerbose: isVerbose }, llmConfiguration.options));
6849
7004
  });
@@ -6914,7 +7069,7 @@ function createLlmToolsFromEnv(options) {
6914
7069
  var configuration = createLlmToolsFromConfigurationFromEnv();
6915
7070
  if (configuration.length === 0) {
6916
7071
  // TODO: [🥃]
6917
- 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 "); }));
7072
+ 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 "); }));
6918
7073
  }
6919
7074
  return createLlmToolsFromConfiguration(configuration, options);
6920
7075
  }
@@ -7140,17 +7295,17 @@ function getLlmToolsForCli(options) {
7140
7295
  function initializeMakeCommand(program) {
7141
7296
  var _this = this;
7142
7297
  var makeCommand = program.command('make');
7143
- makeCommand.description(spaceTrim("\n Makes a new pipeline collection in given folder\n "));
7298
+ makeCommand.description(spaceTrim$1("\n Makes a new pipeline collection in given folder\n "));
7144
7299
  makeCommand.argument('[path]',
7145
7300
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
7146
7301
  'Path to promptbook directory', './promptbook-collection');
7147
7302
  makeCommand.option('--project-name', "Name of the project for whom collection is", 'Untitled Promptbook project');
7148
- makeCommand.option('-f, --format <format>', spaceTrim("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
7303
+ makeCommand.option('-f, --format <format>', spaceTrim$1("\n Output format of builded collection \"javascript\", \"typescript\" or \"json\"\n\n Note: You can use multiple formats separated by comma\n "), 'javascript' /* <- Note: [🏳‍🌈] */);
7149
7304
  makeCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
7150
7305
  makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
7151
7306
  makeCommand.option('--reload-cache', "Use LLM models even if cached ", false);
7152
7307
  makeCommand.option('--verbose', "Is verbose", false);
7153
- makeCommand.option('-o, --out-file <path>', spaceTrim("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), PIPELINE_COLLECTION_BASE_FILENAME);
7308
+ makeCommand.option('-o, --out-file <path>', spaceTrim$1("\n Where to save the builded collection\n\n Note: If you keep it \"".concat(PIPELINE_COLLECTION_BASE_FILENAME, "\" it will be saved in the root of the promptbook directory\n If you set it to a path, it will be saved in that path\n BUT you can use only one format and set correct extension\n ")), PIPELINE_COLLECTION_BASE_FILENAME);
7154
7309
  makeCommand.action(function (path, _a) {
7155
7310
  var projectName = _a.projectName, format = _a.format, validation = _a.validation, reloadCache = _a.reloadCache, verbose = _a.verbose, outFile = _a.outFile;
7156
7311
  return __awaiter(_this, void 0, void 0, function () {
@@ -7255,7 +7410,7 @@ function initializeMakeCommand(program) {
7255
7410
  if (lastChar !== ']') {
7256
7411
  throw new UnexpectedError("Last character of serialized collection should be \"]\" not \"".concat(lastChar, "\""));
7257
7412
  }
7258
- return spaceTrim(collectionJsonString.substring(1, collectionJsonString.length - 1));
7413
+ return spaceTrim$1(collectionJsonString.substring(1, collectionJsonString.length - 1));
7259
7414
  })();
7260
7415
  saveFile = function (extension, content) { return __awaiter(_this, void 0, void 0, function () {
7261
7416
  var filePath;
@@ -7289,14 +7444,14 @@ function initializeMakeCommand(program) {
7289
7444
  case 19:
7290
7445
  if (!(formats.includes('javascript') || formats.includes('js'))) return [3 /*break*/, 21];
7291
7446
  formats = formats.filter(function (format) { return format !== 'javascript' && format !== 'js'; });
7292
- return [4 /*yield*/, saveFile('js', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
7447
+ return [4 /*yield*/, saveFile('js', spaceTrim$1(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(){\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }))];
7293
7448
  case 20:
7294
7449
  (_f.sent()) + '\n';
7295
7450
  _f.label = 21;
7296
7451
  case 21:
7297
7452
  if (!(formats.includes('typescript') || formats.includes('ts'))) return [3 /*break*/, 23];
7298
7453
  formats = formats.filter(function (format) { return format !== 'typescript' && format !== 'ts'; });
7299
- return [4 /*yield*/, saveFile('ts', spaceTrim(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(): PipelineCollection{\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
7454
+ return [4 /*yield*/, saveFile('ts', spaceTrim$1(function (block) { return "\n // ".concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n\n import { createCollectionFromJson } from '@promptbook/core';\n import type { PipelineCollection } from '@promptbook/types';\n\n /**\n * Pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @private internal cache for `getPipelineCollection`\n */\n let pipelineCollection: null | PipelineCollection = null;\n\n\n /**\n * Get pipeline collection for ").concat(projectName, "\n *\n * ").concat(block(GENERATOR_WARNING_BY_PROMPTBOOK_CLI), "\n *\n * @returns {PipelineCollection} Library of promptbooks for ").concat(projectName, "\n */\n export function getPipelineCollection(): PipelineCollection{\n if(pipelineCollection===null){\n pipelineCollection = createCollectionFromJson(\n ").concat(block(collectionJsonItems), "\n );\n }\n\n return pipelineCollection;\n }\n "); }) + '\n')];
7300
7455
  case 22:
7301
7456
  _f.sent();
7302
7457
  _f.label = 23;
@@ -7334,7 +7489,7 @@ function addAutoGeneratedSection(content, options) {
7334
7489
  var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
7335
7490
  var sectionMatch = content.match(sectionRegex);
7336
7491
  if (sectionMatch) {
7337
- return content.replace(sectionRegex, spaceTrim$1(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
7492
+ return content.replace(sectionRegex, spaceTrim(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
7338
7493
  }
7339
7494
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
7340
7495
  if (!placeForSection) {
@@ -7437,7 +7592,7 @@ function renderPromptbookMermaid(pipelineJson, options) {
7437
7592
  }
7438
7593
  return normalizeTo_camelCase('template-' + titleToName(template.title));
7439
7594
  };
7440
- var promptbookMermaid = spaceTrim$1(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.promptTemplates
7595
+ var promptbookMermaid = spaceTrim(function (block) { return "\n\n %% \uD83D\uDD2E Tip: Open this on GitHub or in the VSCode website to see the Mermaid graph visually\n\n flowchart LR\n subgraph \"".concat(pipelineJson.title, "\"\n\n direction TB\n\n input((Input)):::input\n ").concat(block(pipelineJson.promptTemplates
7441
7596
  .flatMap(function (_a) {
7442
7597
  var title = _a.title, dependentParameterNames = _a.dependentParameterNames, resultingParameterName = _a.resultingParameterName;
7443
7598
  return __spreadArray([
@@ -7495,7 +7650,7 @@ function prettifyPipelineString(pipelineString, options) {
7495
7650
  return { href: "#".concat(promptTemplate.name), title: promptTemplate.title };
7496
7651
  },
7497
7652
  });
7498
- promptbookMermaidBlock = spaceTrim$1(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
7653
+ promptbookMermaidBlock = spaceTrim(function (block) { return "\n ```mermaid\n ".concat(block(promptbookMermaid_1), "\n ```\n "); });
7499
7654
  pipelineString = addAutoGeneratedSection(pipelineString, {
7500
7655
  sectionName: 'Graph',
7501
7656
  sectionContent: promptbookMermaidBlock,
@@ -7523,7 +7678,7 @@ function prettifyPipelineString(pipelineString, options) {
7523
7678
  function initializePrettifyCommand(program) {
7524
7679
  var _this = this;
7525
7680
  var prettifyCommand = program.command('prettify');
7526
- prettifyCommand.description(spaceTrim("\n Iterates over promptbooks and does multiple enhancing operations on them:\n\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
7681
+ prettifyCommand.description(spaceTrim$1("\n Iterates over promptbooks and does multiple enhancing operations on them:\n\n 1) Adds Mermaid graph\n 2) Prettifies the markdown\n "));
7527
7682
  prettifyCommand.argument('<filesGlob>',
7528
7683
  // <- TODO: [🧟‍♂️] Unite path to promptbook collection argument
7529
7684
  'Promptbooks to prettify as glob pattern');
@@ -7615,13 +7770,13 @@ function promptbookCli() {
7615
7770
  var program;
7616
7771
  return __generator(this, function (_a) {
7617
7772
  if (!$isRunningInNode()) {
7618
- throw new EnvironmentMismatchError(spaceTrim$1("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
7773
+ throw new EnvironmentMismatchError(spaceTrim("\n Function promptbookCli is initiator of CLI script and should be run in Node.js environment.\n\n - In browser use function exported from `@promptbook/utils` or `@promptbook/core` directly, for example `prettifyPipelineString`.\n\n "));
7619
7774
  }
7620
7775
  program = new commander.Command();
7621
7776
  program.name('promptbook');
7622
7777
  program.alias('ptbk');
7623
7778
  program.version(PROMPTBOOK_VERSION);
7624
- program.description(spaceTrim$1("\n Promptbook utilities for enhancing workflow with promptbooks\n "));
7779
+ program.description(spaceTrim("\n Promptbook utilities for enhancing workflow with promptbooks\n "));
7625
7780
  initializeAboutCommand(program);
7626
7781
  initializeHelloCommand(program);
7627
7782
  initializeMakeCommand(program);
@@ -7751,13 +7906,13 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
7751
7906
  socket.emit('listModels-request', {
7752
7907
  isAnonymous: true,
7753
7908
  llmToolsConfiguration: this.options.llmToolsConfiguration,
7754
- });
7909
+ } /* <- TODO: [🤛] */);
7755
7910
  }
7756
7911
  else {
7757
7912
  socket.emit('listModels-request', {
7758
7913
  isAnonymous: false,
7759
7914
  clientId: this.options.clientId,
7760
- });
7915
+ } /* <- TODO: [🤛] */);
7761
7916
  }
7762
7917
  return [4 /*yield*/, new Promise(function (resolve, reject) {
7763
7918
  socket.on('listModels-response', function (response) {
@@ -7765,7 +7920,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
7765
7920
  socket.disconnect();
7766
7921
  });
7767
7922
  socket.on('error', function (error) {
7768
- reject(new Error(error.errorMessage));
7923
+ reject(deserializeError(error));
7769
7924
  socket.disconnect();
7770
7925
  });
7771
7926
  })];
@@ -7844,16 +7999,14 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
7844
7999
  isAnonymous: true,
7845
8000
  llmToolsConfiguration: this.options.llmToolsConfiguration,
7846
8001
  prompt: prompt,
7847
- // <- TODO: [🛫] `prompt` is NOT fully serializable as JSON, it contains functions which are not serializable
7848
- });
8002
+ } /* <- TODO: [🤛] */);
7849
8003
  }
7850
8004
  else {
7851
8005
  socket.emit('prompt-request', {
7852
8006
  isAnonymous: false,
7853
8007
  clientId: this.options.clientId,
7854
8008
  prompt: prompt,
7855
- // <- TODO: [🛫] `prompt` is NOT fully serializable as JSON, it contains functions which are not serializable
7856
- });
8009
+ } /* <- TODO: [🤛] */);
7857
8010
  }
7858
8011
  return [4 /*yield*/, new Promise(function (resolve, reject) {
7859
8012
  socket.on('prompt-response', function (response) {
@@ -7861,7 +8014,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
7861
8014
  socket.disconnect();
7862
8015
  });
7863
8016
  socket.on('error', function (error) {
7864
- reject(new PipelineExecutionError(error.errorMessage));
8017
+ reject(deserializeError(error));
7865
8018
  socket.disconnect();
7866
8019
  });
7867
8020
  })];
@@ -7876,6 +8029,7 @@ var RemoteLlmExecutionTools = /** @class */ (function () {
7876
8029
  return RemoteLlmExecutionTools;
7877
8030
  }());
7878
8031
  /**
8032
+ * TODO: Maybe use `$asDeeplyFrozenSerializableJson`
7879
8033
  * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
7880
8034
  * TODO: [🍓] Allow to list compatible models with each variant
7881
8035
  * TODO: [🗯] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
@@ -7910,7 +8064,7 @@ function computeUsage(value) {
7910
8064
  * @see https://docs.anthropic.com/en/docs/models-overview
7911
8065
  * @public exported from `@promptbook/anthropic-claude`
7912
8066
  */
7913
- var ANTHROPIC_CLAUDE_MODELS = [
8067
+ var ANTHROPIC_CLAUDE_MODELS = $asDeeplyFrozenSerializableJson('ANTHROPIC_CLAUDE_MODELS', [
7914
8068
  {
7915
8069
  modelVariant: 'CHAT',
7916
8070
  modelTitle: 'Claude 3.5 Sonnet',
@@ -7975,7 +8129,7 @@ var ANTHROPIC_CLAUDE_MODELS = [
7975
8129
  },
7976
8130
  },
7977
8131
  // TODO: !!! Claude 1 and 2 has also completion versions - ask Hoagy
7978
- ];
8132
+ ]);
7979
8133
  /**
7980
8134
  * Note: [🤖] Add models of new variant
7981
8135
  * TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
@@ -8186,7 +8340,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
8186
8340
  // eslint-disable-next-line prefer-const
8187
8341
  complete = getCurrentIsoDate();
8188
8342
  usage = computeAnthropicClaudeUsage(content, '', rawResponse);
8189
- return [2 /*return*/, {
8343
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('AnthropicClaudeExecutionTools ChatPromptResult', {
8190
8344
  content: resultContent,
8191
8345
  modelName: rawResponse.model,
8192
8346
  timing: {
@@ -8198,7 +8352,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
8198
8352
  rawRequest: rawRequest,
8199
8353
  rawResponse: rawResponse,
8200
8354
  // <- [🗯]
8201
- }];
8355
+ })];
8202
8356
  }
8203
8357
  });
8204
8358
  });
@@ -8207,7 +8361,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
8207
8361
  TODO: [👏]
8208
8362
  public async callCompletionModel(
8209
8363
  prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>,
8210
- ): Promise<PromptCompletionResult> {
8364
+ ): Promise<CompletionPromptResult> {
8211
8365
 
8212
8366
  if (this.options.isVerbose) {
8213
8367
  console.info('🖋 Anthropic Claude callCompletionModel call');
@@ -8260,7 +8414,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
8260
8414
 
8261
8415
 
8262
8416
 
8263
- return {
8417
+ return $asDeeplyFrozenSerializableJson('AnthropicClaudeExecutionTools CompletionPromptResult',{
8264
8418
  content: resultContent,
8265
8419
  modelName: rawResponse.model || model,
8266
8420
  timing: {
@@ -8270,7 +8424,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
8270
8424
  usage,
8271
8425
  rawResponse,
8272
8426
  // <- [🗯]
8273
- };
8427
+ });
8274
8428
  }
8275
8429
  */
8276
8430
  // <- Note: [🤖] callXxxModel
@@ -8283,7 +8437,7 @@ var AnthropicClaudeExecutionTools = /** @class */ (function () {
8283
8437
  return modelName.startsWith(defaultModelName);
8284
8438
  });
8285
8439
  if (model === undefined) {
8286
- throw new UnexpectedError(spaceTrim(function (block) {
8440
+ throw new UnexpectedError(spaceTrim$1(function (block) {
8287
8441
  return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(ANTHROPIC_CLAUDE_MODELS.map(function (_a) {
8288
8442
  var modelName = _a.modelName;
8289
8443
  return "- \"".concat(modelName, "\"");
@@ -8392,7 +8546,7 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
8392
8546
  else if (typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ||
8393
8547
  typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ||
8394
8548
  typeof env.AZUREOPENAI_API_KEY === 'string') {
8395
- throw new Error(spaceTrim("\n You must provide all of the following environment variables:\n \n - AZUREOPENAI_RESOURCE_NAME (".concat(typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_DEPLOYMENT_NAME (").concat(typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_API_KEY (").concat(typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined', ") \n ")));
8549
+ throw new Error(spaceTrim$1("\n You must provide all of the following environment variables:\n \n - AZUREOPENAI_RESOURCE_NAME (".concat(typeof env.AZUREOPENAI_RESOURCE_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_DEPLOYMENT_NAME (").concat(typeof env.AZUREOPENAI_DEPLOYMENT_NAME === 'string' ? 'defined' : 'not defined', ")\n - AZUREOPENAI_API_KEY (").concat(typeof env.AZUREOPENAI_API_KEY === 'string' ? 'defined' : 'not defined', ") \n ")));
8396
8550
  }
8397
8551
  return null;
8398
8552
  },
@@ -8407,7 +8561,7 @@ var _AzureOpenAiMetadataRegistration = $llmToolsMetadataRegister.register({
8407
8561
  * @see https://openai.com/api/pricing/
8408
8562
  * @public exported from `@promptbook/openai`
8409
8563
  */
8410
- var OPENAI_MODELS = [
8564
+ var OPENAI_MODELS = $asDeeplyFrozenSerializableJson('OPENAI_MODELS', [
8411
8565
  /*/
8412
8566
  {
8413
8567
  modelTitle: 'dall-e-3',
@@ -8735,7 +8889,7 @@ var OPENAI_MODELS = [
8735
8889
  },
8736
8890
  },
8737
8891
  /**/
8738
- ];
8892
+ ]);
8739
8893
  /**
8740
8894
  * Note: [🤖] Add models of new variant
8741
8895
  * TODO: [🧠] Some mechanism to propagate unsureness
@@ -8903,7 +9057,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
8903
9057
  input: __assign({ tokensCount: uncertainNumber((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.promptTokens) }, computeUsageCounts(prompt.content)),
8904
9058
  output: __assign({ tokensCount: uncertainNumber((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completionTokens) }, computeUsageCounts(prompt.content)),
8905
9059
  };
8906
- return [2 /*return*/, {
9060
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('AzureOpenAiExecutionTools ChatPromptResult', {
8907
9061
  content: resultContent,
8908
9062
  modelName: modelName,
8909
9063
  timing: {
@@ -8913,9 +9067,9 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
8913
9067
  usage: usage,
8914
9068
  rawPromptContent: rawPromptContent,
8915
9069
  rawRequest: rawRequest,
8916
- rawResponse: rawResponse,
9070
+ rawResponse: __assign(__assign({}, rawResponse), { created: rawResponse.created.toISOString() }),
8917
9071
  // <- [🗯]
8918
- }];
9072
+ })];
8919
9073
  case 4:
8920
9074
  error_1 = _c.sent();
8921
9075
  throw this.transformAzureError(error_1);
@@ -8990,7 +9144,7 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
8990
9144
  input: __assign({ tokensCount: uncertainNumber((_a = rawResponse.usage) === null || _a === void 0 ? void 0 : _a.promptTokens) }, computeUsageCounts(prompt.content)),
8991
9145
  output: __assign({ tokensCount: uncertainNumber((_b = rawResponse.usage) === null || _b === void 0 ? void 0 : _b.completionTokens) }, computeUsageCounts(prompt.content)),
8992
9146
  };
8993
- return [2 /*return*/, {
9147
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('AzureOpenAiExecutionTools CompletionPromptResult', {
8994
9148
  content: resultContent,
8995
9149
  modelName: modelName,
8996
9150
  timing: {
@@ -9000,9 +9154,9 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
9000
9154
  usage: usage,
9001
9155
  rawPromptContent: rawPromptContent,
9002
9156
  rawRequest: rawRequest,
9003
- rawResponse: rawResponse,
9157
+ rawResponse: __assign(__assign({}, rawResponse), { created: rawResponse.created.toISOString() }),
9004
9158
  // <- [🗯]
9005
- }];
9159
+ })];
9006
9160
  case 4:
9007
9161
  error_2 = _c.sent();
9008
9162
  throw this.transformAzureError(error_2);
@@ -9016,11 +9170,14 @@ var AzureOpenAiExecutionTools = /** @class */ (function () {
9016
9170
  * Changes Azure error (which is not propper Error but object) to propper Error
9017
9171
  */
9018
9172
  AzureOpenAiExecutionTools.prototype.transformAzureError = function (azureError) {
9173
+ if (azureError instanceof UnexpectedError) {
9174
+ return azureError;
9175
+ }
9019
9176
  if (typeof azureError !== 'object' || azureError === null) {
9020
9177
  return new PipelineExecutionError("Unknown Azure OpenAI error");
9021
9178
  }
9022
9179
  var code = azureError.code, message = azureError.message;
9023
- return new PipelineExecutionError("".concat(code, ": ").concat(message));
9180
+ return new PipelineExecutionError("".concat(code || '(No Azure error code)', ": ").concat(message));
9024
9181
  };
9025
9182
  return AzureOpenAiExecutionTools;
9026
9183
  }());
@@ -9282,7 +9439,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
9282
9439
  if (resultContent === null) {
9283
9440
  throw new PipelineExecutionError('No response message from OpenAI');
9284
9441
  }
9285
- return [2 /*return*/, {
9442
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools ChatPromptResult', {
9286
9443
  content: resultContent,
9287
9444
  modelName: rawResponse.model || modelName,
9288
9445
  timing: {
@@ -9294,7 +9451,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
9294
9451
  rawRequest: rawRequest,
9295
9452
  rawResponse: rawResponse,
9296
9453
  // <- [🗯]
9297
- }];
9454
+ })];
9298
9455
  }
9299
9456
  });
9300
9457
  });
@@ -9351,7 +9508,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
9351
9508
  // eslint-disable-next-line prefer-const
9352
9509
  complete = getCurrentIsoDate();
9353
9510
  usage = computeOpenAiUsage(content, resultContent || '', rawResponse);
9354
- return [2 /*return*/, {
9511
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools CompletionPromptResult', {
9355
9512
  content: resultContent,
9356
9513
  modelName: rawResponse.model || modelName,
9357
9514
  timing: {
@@ -9363,7 +9520,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
9363
9520
  rawRequest: rawRequest,
9364
9521
  rawResponse: rawResponse,
9365
9522
  // <- [🗯]
9366
- }];
9523
+ })];
9367
9524
  }
9368
9525
  });
9369
9526
  });
@@ -9411,7 +9568,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
9411
9568
  // eslint-disable-next-line prefer-const
9412
9569
  complete = getCurrentIsoDate();
9413
9570
  usage = computeOpenAiUsage(content, '', rawResponse);
9414
- return [2 /*return*/, {
9571
+ return [2 /*return*/, $asDeeplyFrozenSerializableJson('OpenAiExecutionTools EmbeddingPromptResult', {
9415
9572
  content: resultContent,
9416
9573
  modelName: rawResponse.model || modelName,
9417
9574
  timing: {
@@ -9423,7 +9580,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
9423
9580
  rawRequest: rawRequest,
9424
9581
  rawResponse: rawResponse,
9425
9582
  // <- [🗯]
9426
- }];
9583
+ })];
9427
9584
  }
9428
9585
  });
9429
9586
  });
@@ -9438,7 +9595,7 @@ var OpenAiExecutionTools = /** @class */ (function () {
9438
9595
  return modelName === defaultModelName;
9439
9596
  });
9440
9597
  if (model === undefined) {
9441
- throw new UnexpectedError(spaceTrim(function (block) {
9598
+ throw new UnexpectedError(spaceTrim$1(function (block) {
9442
9599
  return "\n Cannot find model in OpenAI models with name \"".concat(defaultModelName, "\" which should be used as default.\n\n Available models:\n ").concat(block(OPENAI_MODELS.map(function (_a) {
9443
9600
  var modelName = _a.modelName;
9444
9601
  return "- \"".concat(modelName, "\"");