@promptbook/cli 0.65.0 → 0.66.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.
package/umd/index.umd.js CHANGED
@@ -39,7 +39,7 @@
39
39
  /**
40
40
  * The version of the Promptbook library
41
41
  */
42
- var PROMPTBOOK_VERSION = '0.65.0-7';
42
+ var PROMPTBOOK_VERSION = '0.65.0';
43
43
  // TODO: !!!! List here all the versions and annotate + put into script
44
44
 
45
45
  /*! *****************************************************************************
@@ -177,34 +177,25 @@
177
177
  return EnvironmentMismatchError;
178
178
  }(Error));
179
179
 
180
- /**
181
- * Detects if the code is running in a browser environment in main thread (Not in a web worker)
182
- *
183
- * @public exported from `@promptbook/utils`
184
- */
185
- new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
186
180
  /**
187
181
  * Detects if the code is running in a Node.js environment
188
182
  *
189
- * @public exported from `@promptbook/utils`
190
- */
191
- var isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
192
- /**
193
- * Detects if the code is running in a web worker
183
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
194
184
  *
195
185
  * @public exported from `@promptbook/utils`
196
186
  */
197
- new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
187
+ var $isRunningInNode = new Function("\n try {\n return this === global;\n } catch (e) {\n return false;\n }\n");
198
188
 
199
189
  /**
200
190
  * @@@
201
191
  *
192
+ * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
202
193
  * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
203
194
  *
204
195
  * @returns The same object as the input, but deeply frozen
205
196
  * @public exported from `@promptbook/utils`
206
197
  */
207
- function deepFreeze(objectValue) {
198
+ function $deepFreeze(objectValue) {
208
199
  var e_1, _a;
209
200
  var propertyNames = Object.getOwnPropertyNames(objectValue);
210
201
  try {
@@ -212,7 +203,7 @@
212
203
  var propertyName = propertyNames_1_1.value;
213
204
  var value = objectValue[propertyName];
214
205
  if (value && typeof value === 'object') {
215
- deepFreeze(value);
206
+ $deepFreeze(value);
216
207
  }
217
208
  }
218
209
  }
@@ -235,7 +226,7 @@
235
226
  * @private this is in comparison to `deepFreeze` a more specific utility and maybe not very good practice to use without specific reason and considerations
236
227
  */
237
228
  function deepFreezeWithSameType(objectValue) {
238
- return deepFreeze(objectValue);
229
+ return $deepFreeze(objectValue);
239
230
  }
240
231
  /**
241
232
  * TODO: [🧠] Is there a way how to meaningfully test this utility
@@ -309,7 +300,7 @@
309
300
  *
310
301
  * @public exported from `@promptbook/core`
311
302
  */
312
- var RESERVED_PARAMETER_NAMES = deepFreeze([
303
+ var RESERVED_PARAMETER_NAMES = $deepFreeze([
313
304
  'content',
314
305
  'context',
315
306
  'knowledge',
@@ -692,7 +683,7 @@
692
683
  *
693
684
  * @public exported from `@promptbook/core`
694
685
  */
695
- var ZERO_USAGE = deepFreeze({
686
+ var ZERO_USAGE = $deepFreeze({
696
687
  price: { value: 0 },
697
688
  input: {
698
689
  tokensCount: { value: 0 },
@@ -860,7 +851,7 @@
860
851
  });
861
852
  }
862
853
 
863
- var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.65.0-7",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.65.0-7",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.65.0-7",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.65.0-7",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"}];
854
+ var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.65.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.65.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.65.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.65.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"}];
864
855
 
865
856
  /**
866
857
  * This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
@@ -2965,20 +2956,20 @@
2965
2956
  case 'EMBEDDING': return [3 /*break*/, 12];
2966
2957
  }
2967
2958
  return [3 /*break*/, 14];
2968
- case 8: return [4 /*yield*/, llmTools.callChatModel(deepFreeze(prompt))];
2959
+ case 8: return [4 /*yield*/, llmTools.callChatModel($deepFreeze(prompt))];
2969
2960
  case 9:
2970
2961
  chatResult = _u.sent();
2971
2962
  // TODO: [🍬] Destroy chatThread
2972
2963
  result = chatResult;
2973
2964
  resultString = chatResult.content;
2974
2965
  return [3 /*break*/, 15];
2975
- case 10: return [4 /*yield*/, llmTools.callCompletionModel(deepFreeze(prompt))];
2966
+ case 10: return [4 /*yield*/, llmTools.callCompletionModel($deepFreeze(prompt))];
2976
2967
  case 11:
2977
2968
  completionResult = _u.sent();
2978
2969
  result = completionResult;
2979
2970
  resultString = completionResult.content;
2980
2971
  return [3 /*break*/, 15];
2981
- case 12: return [4 /*yield*/, llmTools.callEmbeddingModel(deepFreeze(prompt))];
2972
+ case 12: return [4 /*yield*/, llmTools.callEmbeddingModel($deepFreeze(prompt))];
2982
2973
  case 13:
2983
2974
  embeddingResult = _u.sent();
2984
2975
  result = embeddingResult;
@@ -3006,7 +2997,7 @@
3006
2997
  _u.label = 19;
3007
2998
  case 19:
3008
2999
  _u.trys.push([19, 21, , 22]);
3009
- return [4 /*yield*/, scriptTools.execute(deepFreeze({
3000
+ return [4 /*yield*/, scriptTools.execute($deepFreeze({
3010
3001
  scriptLanguage: currentTemplate.contentLanguage,
3011
3002
  script: preparedContent,
3012
3003
  parameters: parameters,
@@ -3054,7 +3045,7 @@
3054
3045
  if (tools.userInterface === undefined) {
3055
3046
  throw new PipelineExecutionError('User interface tools are not available');
3056
3047
  }
3057
- return [4 /*yield*/, tools.userInterface.promptDialog(deepFreeze({
3048
+ return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
3058
3049
  promptTitle: currentTemplate.title,
3059
3050
  promptMessage: replaceParameters(currentTemplate.description || '', parameters),
3060
3051
  defaultValue: replaceParameters(preparedContent, parameters),
@@ -3849,7 +3840,9 @@
3849
3840
  promptTemplates = pipeline.promptTemplates, parameters = pipeline.parameters, knowledgePiecesCount = pipeline.knowledgePiecesCount;
3850
3841
  // TODO: !!!!! Apply samples to each template (if missing and is for the template defined)
3851
3842
  TODO_USE(parameters);
3852
- promptTemplatesPrepared = new Array(promptTemplates.length);
3843
+ promptTemplatesPrepared = new Array(
3844
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
3845
+ promptTemplates.length);
3853
3846
  return [4 /*yield*/, forEachAsync(promptTemplates, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (template, index) { return __awaiter(_this, void 0, void 0, function () {
3854
3847
  var dependentParameterNames, preparedContent, preparedTemplate;
3855
3848
  return __generator(this, function (_a) {
@@ -3922,7 +3915,9 @@
3922
3915
  // <- TODO: [🧊]
3923
3916
  currentPreparation,
3924
3917
  ];
3925
- preparedPersonas = new Array(personas.length);
3918
+ preparedPersonas = new Array(
3919
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
3920
+ personas.length);
3926
3921
  return [4 /*yield*/, forEachAsync(personas, { maxParallelCount: maxParallelCount /* <- TODO: [🪂] When there are subtasks, this maximul limit can be broken */ }, function (persona, index) { return __awaiter(_this, void 0, void 0, function () {
3927
3922
  var modelRequirements, preparedPersona;
3928
3923
  return __generator(this, function (_a) {
@@ -6002,9 +5997,11 @@
6002
5997
  /**
6003
5998
  * Checks if the file exists
6004
5999
  *
6000
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
6001
+ *
6005
6002
  * @private within the repository
6006
6003
  */
6007
- function isFileExisting(filePath) {
6004
+ function $isFileExisting(filePath) {
6008
6005
  return __awaiter(this, void 0, void 0, function () {
6009
6006
  var isReadAccessAllowed, isFile;
6010
6007
  return __generator(this, function (_a) {
@@ -6036,9 +6033,11 @@
6036
6033
  /**
6037
6034
  * Checks if the directory exists
6038
6035
  *
6036
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
6037
+ *
6039
6038
  * @private within the repository
6040
6039
  */
6041
- function isDirectoryExisting(directoryPath) {
6040
+ function $isDirectoryExisting(directoryPath) {
6042
6041
  return __awaiter(this, void 0, void 0, function () {
6043
6042
  var isReadAccessAllowed, isDirectory;
6044
6043
  return __generator(this, function (_a) {
@@ -6071,18 +6070,20 @@
6071
6070
  /**
6072
6071
  * Reads all files in the directory
6073
6072
  *
6073
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the filesystem
6074
+ *
6074
6075
  * @param path
6075
6076
  * @param isRecursive
6076
6077
  * @returns List of all files in the directory
6077
6078
  * @private internal function of `createCollectionFromDirectory`
6078
6079
  */
6079
- function listAllFiles(path, isRecursive) {
6080
+ function $listAllFiles(path, isRecursive) {
6080
6081
  return __awaiter(this, void 0, void 0, function () {
6081
6082
  var dirents, fileNames, _a, _b, dirent, subPath, _c, _d, _e, _f, e_1_1;
6082
6083
  var e_1, _g;
6083
6084
  return __generator(this, function (_h) {
6084
6085
  switch (_h.label) {
6085
- case 0: return [4 /*yield*/, isDirectoryExisting(path)];
6086
+ case 0: return [4 /*yield*/, $isDirectoryExisting(path)];
6086
6087
  case 1:
6087
6088
  if (!(_h.sent())) {
6088
6089
  throw new Error("Directory \"".concat(path, "\" does not exist or is not readable"));
@@ -6110,7 +6111,7 @@
6110
6111
  _d = (_c = fileNames.push).apply;
6111
6112
  _e = [fileNames];
6112
6113
  _f = [[]];
6113
- return [4 /*yield*/, listAllFiles(subPath, isRecursive)];
6114
+ return [4 /*yield*/, $listAllFiles(subPath, isRecursive)];
6114
6115
  case 5:
6115
6116
  _d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
6116
6117
  _h.label = 6;
@@ -6242,11 +6243,11 @@
6242
6243
  return __generator(this, function (_f) {
6243
6244
  switch (_f.label) {
6244
6245
  case 0:
6245
- if (!isRunningInNode()) {
6246
+ if (!$isRunningInNode()) {
6246
6247
  throw new Error('Function `createCollectionFromDirectory` can only be run in Node.js environment because it reads the file system.');
6247
6248
  }
6248
6249
  makedLibraryFilePath = path.join(path$1, "".concat(PIPELINE_COLLECTION_BASE_FILENAME, ".json"));
6249
- return [4 /*yield*/, isFileExisting(makedLibraryFilePath)];
6250
+ return [4 /*yield*/, $isFileExisting(makedLibraryFilePath)];
6250
6251
  case 1:
6251
6252
  if (!(_f.sent())) {
6252
6253
  console.info(colors__default["default"].yellow("Tip: Prebuild your pipeline collection (file with supposed prebuild ".concat(makedLibraryFilePath, " not found) with CLI util \"ptbk make\" to speed up the collection creation.")));
@@ -6266,7 +6267,7 @@
6266
6267
  if (isVerbose) {
6267
6268
  console.info(colors__default["default"].cyan("Creating pipeline collection from path ".concat(path$1.split('\\').join('/'))));
6268
6269
  }
6269
- return [4 /*yield*/, listAllFiles(path$1, isRecursive)];
6270
+ return [4 /*yield*/, $listAllFiles(path$1, isRecursive)];
6270
6271
  case 1:
6271
6272
  fileNames = _b.sent();
6272
6273
  // Note: First load all .ptbk.json and then .ptbk.md files
@@ -6501,7 +6502,7 @@
6501
6502
  var FilesStorage = /** @class */ (function () {
6502
6503
  function FilesStorage(options) {
6503
6504
  this.options = options;
6504
- if (!isRunningInNode()) {
6505
+ if (!$isRunningInNode()) {
6505
6506
  throw new EnvironmentMismatchError("FilesStorage works only in Node.js environment");
6506
6507
  }
6507
6508
  }
@@ -6524,7 +6525,7 @@
6524
6525
  switch (_a.label) {
6525
6526
  case 0:
6526
6527
  filename = this.getFilenameForKey(key);
6527
- return [4 /*yield*/, isFileExisting(filename)];
6528
+ return [4 /*yield*/, $isFileExisting(filename)];
6528
6529
  case 1:
6529
6530
  if (!(_a.sent())) {
6530
6531
  return [2 /*return*/, null];
@@ -6621,7 +6622,9 @@
6621
6622
  */
6622
6623
  RemoteLlmExecutionTools.prototype.makeConnection = function () {
6623
6624
  var _this = this;
6624
- return new Promise(function (resolve, reject) {
6625
+ return new Promise(
6626
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
6627
+ function (resolve, reject) {
6625
6628
  var socket = socket_ioClient.io(_this.options.remoteUrl, {
6626
6629
  path: _this.options.path,
6627
6630
  // path: `${this.remoteUrl.pathname}/socket.io`,
@@ -6743,12 +6746,21 @@
6743
6746
  /**
6744
6747
  * List of available Anthropic Claude models with pricing
6745
6748
  *
6746
- * Note: Done at 2024-05-25
6749
+ * Note: Done at 2024-08-16
6747
6750
  *
6748
6751
  * @see https://docs.anthropic.com/en/docs/models-overview
6749
6752
  * @public exported from `@promptbook/anthropic-claude`
6750
6753
  */
6751
6754
  var ANTHROPIC_CLAUDE_MODELS = [
6755
+ {
6756
+ modelVariant: 'CHAT',
6757
+ modelTitle: 'Claude 3.5 Sonnet',
6758
+ modelName: 'claude-3-5-sonnet-20240620',
6759
+ pricing: {
6760
+ prompt: computeUsage("$3.00 / 1M tokens"),
6761
+ output: computeUsage("$15.00 / 1M tokens"),
6762
+ },
6763
+ },
6752
6764
  {
6753
6765
  modelVariant: 'CHAT',
6754
6766
  modelTitle: 'Claude 3 Opus',
@@ -6810,7 +6822,7 @@
6810
6822
  * TODO: [🧠] !!! Add embedding models OR Anthropic has only chat+completion models?
6811
6823
  * TODO: [🧠] Some mechanism to propagate unsureness
6812
6824
  * TODO: [🧠][👮‍♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
6813
- * TODO: [🕚] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
6825
+ * TODO: [🎰] Some mechanism to auto-update available models
6814
6826
  */
6815
6827
 
6816
6828
  /**
@@ -6874,7 +6886,9 @@
6874
6886
  var anthropicOptions = __assign({}, options);
6875
6887
  delete anthropicOptions.isVerbose;
6876
6888
  delete anthropicOptions.isProxied;
6877
- this.client = new Anthropic__default["default"](anthropicOptions);
6889
+ this.client = new Anthropic__default["default"](
6890
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
6891
+ anthropicOptions);
6878
6892
  }
6879
6893
  Object.defineProperty(AnthropicClaudeExecutionTools.prototype, "title", {
6880
6894
  get: function () {
@@ -6895,7 +6909,7 @@
6895
6909
  */
6896
6910
  AnthropicClaudeExecutionTools.prototype.callChatModel = function (prompt) {
6897
6911
  return __awaiter(this, void 0, void 0, function () {
6898
- var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, resultContent, usage;
6912
+ var content, parameters, modelRequirements, modelName, rawPromptContent, rawRequest, start, complete, rawResponse, contentBlock, resultContent, usage;
6899
6913
  return __generator(this, function (_a) {
6900
6914
  switch (_a.label) {
6901
6915
  case 0:
@@ -6941,11 +6955,16 @@
6941
6955
  if (rawResponse.content.length > 1) {
6942
6956
  throw new PipelineExecutionError('More than one content blocks from Anthropic Claude');
6943
6957
  }
6944
- resultContent = rawResponse.content[0].text;
6958
+ contentBlock = rawResponse.content[0];
6959
+ if (contentBlock.type !== 'text') {
6960
+ throw new PipelineExecutionError("Returned content is not \"text\" type but \"".concat(contentBlock.type, "\""));
6961
+ }
6962
+ console.log('!!!!!! rawResponse.usage', rawResponse.usage);
6963
+ resultContent = contentBlock.text;
6945
6964
  // eslint-disable-next-line prefer-const
6946
6965
  complete = getCurrentIsoDate();
6947
6966
  usage = {
6948
- price: { value: 0, isUncertain: true } /* <- TODO: [🐞] Compute usage */,
6967
+ price: { value: 0, isUncertain: true } /* <- TODO: [🐞] !!!!!! Compute usage */,
6949
6968
  input: __assign({ tokensCount: uncertainNumber(rawResponse.usage.input_tokens) }, computeUsageCounts(prompt.content)),
6950
6969
  output: __assign({ tokensCount: uncertainNumber(rawResponse.usage.output_tokens) }, computeUsageCounts(prompt.content)),
6951
6970
  };
@@ -7096,7 +7115,9 @@
7096
7115
  },
7097
7116
  ], models: ANTHROPIC_CLAUDE_MODELS }));
7098
7117
  }
7099
- return new AnthropicClaudeExecutionTools(options);
7118
+ return new AnthropicClaudeExecutionTools(
7119
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
7120
+ options);
7100
7121
  }
7101
7122
  /**
7102
7123
  * TODO: [🧠] !!!! Make anonymous this with all LLM providers
@@ -7445,7 +7466,8 @@
7445
7466
  /**
7446
7467
  * Note: [🤖] Add models of new variant
7447
7468
  * TODO: [🧠] Some mechanism to propagate unsureness
7448
- * TODO: [🕚][👮‍♀️] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
7469
+ * TODO: [🎰] Some mechanism to auto-update available models
7470
+ * TODO: [🎰][👮‍♀️] Make this list dynamic - dynamically can be listed modelNames but not modelVariant, legacy status, context length and pricing
7449
7471
  * TODO: [🧠][👮‍♀️] Put here more info like description, isVision, trainingDateCutoff, languages, strengths ( Top-level performance, intelligence, fluency, and understanding), contextWindow,...
7450
7472
  * @see https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4
7451
7473
  * @see https://openai.com/api/pricing/
@@ -7468,7 +7490,11 @@
7468
7490
  */
7469
7491
  function AzureOpenAiExecutionTools(options) {
7470
7492
  this.options = options;
7471
- this.client = new openai.OpenAIClient("https://".concat(options.resourceName, ".openai.azure.com/"), new openai.AzureKeyCredential(options.apiKey));
7493
+ this.client = new openai.OpenAIClient(
7494
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
7495
+ "https://".concat(options.resourceName, ".openai.azure.com/"), new openai.AzureKeyCredential(
7496
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
7497
+ options.apiKey));
7472
7498
  }
7473
7499
  Object.defineProperty(AzureOpenAiExecutionTools.prototype, "title", {
7474
7500
  get: function () {
@@ -8051,7 +8077,11 @@
8051
8077
  return new OpenAiExecutionTools(__assign(__assign({}, options), { dangerouslyAllowBrowser: true /* <- TODO: [🧠] !!! Some mechanism for auto-detection of browser, maybe hide in `OpenAiExecutionTools` */ }));
8052
8078
  },
8053
8079
  createAnthropicClaudeExecutionTools: createAnthropicClaudeExecutionTools,
8054
- createAzureOpenAiExecutionTools: function (options) { return new AzureOpenAiExecutionTools(options); },
8080
+ createAzureOpenAiExecutionTools: function (options) {
8081
+ return new AzureOpenAiExecutionTools(
8082
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
8083
+ options);
8084
+ },
8055
8085
  // <- Note: [🦑] Add here new LLM provider
8056
8086
  };
8057
8087
  /**
@@ -8097,7 +8127,7 @@
8097
8127
  * @public exported from `@promptbook/node`
8098
8128
  */
8099
8129
  function createLlmToolsFromConfigurationFromEnv() {
8100
- if (!isRunningInNode()) {
8130
+ if (!$isRunningInNode()) {
8101
8131
  throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
8102
8132
  }
8103
8133
  dotenv__namespace.config();
@@ -8151,7 +8181,7 @@
8151
8181
  */
8152
8182
  function createLlmToolsFromEnv(options) {
8153
8183
  if (options === void 0) { options = {}; }
8154
- if (!isRunningInNode()) {
8184
+ if (!$isRunningInNode()) {
8155
8185
  throw new EnvironmentMismatchError('Function `createLlmToolsFromEnv` works only in Node.js environment');
8156
8186
  }
8157
8187
  var configuration = createLlmToolsFromConfigurationFromEnv();
@@ -8225,6 +8255,8 @@
8225
8255
  /**
8226
8256
  * Simple wrapper `new Date().toISOString()`
8227
8257
  *
8258
+ * Note: `$` is used to indicate that this function is not a pure function - it is not deterministic because it depends on the current time
8259
+ *
8228
8260
  * @returns string_date branded type
8229
8261
  * @public exported from `@promptbook/utils`
8230
8262
  */
@@ -8244,7 +8276,11 @@
8244
8276
  function cacheLlmTools(llmTools, options) {
8245
8277
  var _this = this;
8246
8278
  if (options === void 0) { options = {}; }
8247
- var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a, _b = options.isReloaded, isReloaded = _b === void 0 ? false : _b;
8279
+ var _a = options.storage, storage = _a === void 0 ? new MemoryStorage() : _a,
8280
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
8281
+ _b = options.isReloaded,
8282
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
8283
+ isReloaded = _b === void 0 ? false : _b;
8248
8284
  var proxyTools = __assign(__assign({}, llmTools), {
8249
8285
  // <- Note: [🥫]
8250
8286
  get title() {
@@ -8349,14 +8385,16 @@
8349
8385
  * @private within the repository - for CLI utils
8350
8386
  */
8351
8387
  function getLlmToolsForCli(options) {
8352
- if (!isRunningInNode()) {
8388
+ if (!$isRunningInNode()) {
8353
8389
  throw new EnvironmentMismatchError('Function `getLlmToolsForTestingAndScriptsAndPlayground` works only in Node.js environment');
8354
8390
  }
8355
8391
  var _a = (options !== null && options !== void 0 ? options : {}).isCacheReloaded, isCacheReloaded = _a === void 0 ? false : _a;
8356
8392
  return cacheLlmTools(countTotalUsage(
8357
8393
  // <- Note: for example here we don`t want the [🌯]
8358
8394
  createLlmToolsFromEnv()), {
8359
- storage: new FilesStorage({ cacheFolderPath: path.join(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
8395
+ storage: new FilesStorage(
8396
+ // <- TODO: [🧱] Implement in a functional (not new Class) way
8397
+ { cacheFolderPath: path.join(process.cwd(), EXECUTIONS_CACHE_DIRNAME) }),
8360
8398
  isReloaded: isCacheReloaded,
8361
8399
  });
8362
8400
  }
@@ -8849,7 +8887,7 @@
8849
8887
  return __awaiter(this, void 0, void 0, function () {
8850
8888
  var program;
8851
8889
  return __generator(this, function (_a) {
8852
- if (!isRunningInNode()) {
8890
+ if (!$isRunningInNode()) {
8853
8891
  throw new EnvironmentMismatchError(spaceTrim.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 "));
8854
8892
  }
8855
8893
  program = new commander__default["default"].Command();