@promptbook/cli 0.63.0-5 → 0.63.0-7
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/esm/index.es.js +226 -106
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +2 -0
- package/esm/typings/src/cli/cli-commands/about.d.ts +11 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +3 -0
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +1 -0
- package/esm/typings/src/cli/test/ptbk.d.ts +2 -0
- package/esm/typings/src/cli/test/ptbk.test.d.ts +1 -0
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +1 -0
- package/esm/typings/src/config.d.ts +8 -0
- package/esm/typings/src/conversion/validation/_importPipeline.d.ts +3 -0
- package/esm/typings/src/utils/files/isDirectoryExisting.d.ts +13 -0
- package/esm/typings/src/utils/files/isDirectoryExisting.test.d.ts +1 -0
- package/esm/typings/src/utils/files/isFileExisting.d.ts +12 -0
- package/esm/typings/src/utils/files/isFileExisting.test.d.ts +1 -0
- package/esm/typings/src/utils/files/listAllFiles.d.ts +1 -0
- package/esm/typings/src/utils/files/listAllFiles.test.d.ts +1 -0
- package/package.json +1 -1
- package/umd/index.umd.js +225 -105
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -2,7 +2,7 @@ import commander from 'commander';
|
|
|
2
2
|
import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
|
|
3
3
|
import colors from 'colors';
|
|
4
4
|
import { forTime } from 'waitasecond';
|
|
5
|
-
import {
|
|
5
|
+
import { stat, access, constants, readdir, readFile, writeFile, mkdir, unlink } from 'fs/promises';
|
|
6
6
|
import { join as join$1, dirname } from 'path';
|
|
7
7
|
import { format } from 'prettier';
|
|
8
8
|
import parserHtml from 'prettier/parser-html';
|
|
@@ -14,10 +14,11 @@ import Anthropic from '@anthropic-ai/sdk';
|
|
|
14
14
|
import OpenAI from 'openai';
|
|
15
15
|
import glob from 'glob-promise';
|
|
16
16
|
|
|
17
|
+
// ⚠️ WARNING: This code has been generated so that any manual changes will be overwritten
|
|
17
18
|
/**
|
|
18
19
|
* The version of the Promptbook library
|
|
19
20
|
*/
|
|
20
|
-
var PROMPTBOOK_VERSION = '0.63.0-
|
|
21
|
+
var PROMPTBOOK_VERSION = '0.63.0-6';
|
|
21
22
|
// TODO: !!!! List here all the versions and annotate + put into script
|
|
22
23
|
|
|
23
24
|
/*! *****************************************************************************
|
|
@@ -174,66 +175,6 @@ var isRunningInNode = new Function("\n try {\n return this === global;
|
|
|
174
175
|
*/
|
|
175
176
|
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");
|
|
176
177
|
|
|
177
|
-
/**
|
|
178
|
-
* Initializes testing `hello` command for Promptbook CLI utilities
|
|
179
|
-
*
|
|
180
|
-
* @private internal function of `promptbookCli`
|
|
181
|
-
*/
|
|
182
|
-
function initializeHelloCommand(program) {
|
|
183
|
-
var _this = this;
|
|
184
|
-
var helloCommand = program.command('hello');
|
|
185
|
-
helloCommand.description(spaceTrim("\n Just command for testing\n "));
|
|
186
|
-
helloCommand.argument('<name>', 'Your name');
|
|
187
|
-
helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
|
|
188
|
-
helloCommand.action(function (name, _a) {
|
|
189
|
-
var greeting = _a.greeting;
|
|
190
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
191
|
-
return __generator(this, function (_b) {
|
|
192
|
-
switch (_b.label) {
|
|
193
|
-
case 0:
|
|
194
|
-
console.info(colors.cyan("".concat(greeting, " ").concat(name)));
|
|
195
|
-
return [4 /*yield*/, forTime(1000)];
|
|
196
|
-
case 1:
|
|
197
|
-
_b.sent();
|
|
198
|
-
console.info(colors.rainbow("Nice to meet you!"));
|
|
199
|
-
process.exit(0);
|
|
200
|
-
return [2 /*return*/];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
208
|
-
*/
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Converts PipelineCollection to serialized JSON
|
|
212
|
-
*
|
|
213
|
-
* Note: Functions `collectionToJson` and `createCollectionFromJson` are complementary
|
|
214
|
-
*
|
|
215
|
-
* @public exported from `@promptbook/core`
|
|
216
|
-
*/
|
|
217
|
-
function collectionToJson(collection) {
|
|
218
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
-
var pipelineUrls, promptbooks;
|
|
220
|
-
return __generator(this, function (_a) {
|
|
221
|
-
switch (_a.label) {
|
|
222
|
-
case 0: return [4 /*yield*/, collection.listPipelines()];
|
|
223
|
-
case 1:
|
|
224
|
-
pipelineUrls = _a.sent();
|
|
225
|
-
return [4 /*yield*/, Promise.all(pipelineUrls.map(function (url) { return collection.getPipelineByUrl(url); }))];
|
|
226
|
-
case 2:
|
|
227
|
-
promptbooks = _a.sent();
|
|
228
|
-
return [2 /*return*/, promptbooks];
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* TODO: [🧠] Maybe clear `sourceFile` or clear when exposing through API or remote server
|
|
235
|
-
*/
|
|
236
|
-
|
|
237
178
|
/**
|
|
238
179
|
* @@@
|
|
239
180
|
*
|
|
@@ -285,6 +226,14 @@ function deepFreezeWithSameType(objectValue) {
|
|
|
285
226
|
* @private within the repository
|
|
286
227
|
*/
|
|
287
228
|
var GENERATOR_WARNING = "\u26A0\uFE0F WARNING: This code has been generated so that any manual changes will be overwritten";
|
|
229
|
+
/**
|
|
230
|
+
* Claim for the Promptbook
|
|
231
|
+
*
|
|
232
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
233
|
+
*
|
|
234
|
+
* @public exported from `@promptbook/core`
|
|
235
|
+
*/
|
|
236
|
+
var CLAIM = "Supercharge LLM models with Promptbook";
|
|
288
237
|
/**
|
|
289
238
|
* Warning message for the generated sections and files files
|
|
290
239
|
*
|
|
@@ -362,6 +311,91 @@ var RESERVED_PARAMETER_MISSING_VALUE = 'MISSING-' + REPLACING_NONCE;
|
|
|
362
311
|
*/
|
|
363
312
|
var RESERVED_PARAMETER_RESTRICTED = 'RESTRICTED-' + REPLACING_NONCE;
|
|
364
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Initializes `about` command for Promptbook CLI utilities
|
|
316
|
+
*
|
|
317
|
+
* @private internal function of `promptbookCli`
|
|
318
|
+
*/
|
|
319
|
+
function initializeAboutCommand(program) {
|
|
320
|
+
var _this = this;
|
|
321
|
+
var makeCommand = program.command('about');
|
|
322
|
+
makeCommand.description(spaceTrim("\n Tells about Promptbook CLI and its abilities\n "));
|
|
323
|
+
makeCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
324
|
+
return __generator(this, function (_a) {
|
|
325
|
+
console.info(colors.cyan("Promptbook"));
|
|
326
|
+
console.info(colors.cyan(CLAIM));
|
|
327
|
+
console.info(colors.cyan("Version: ".concat(PROMPTBOOK_VERSION)));
|
|
328
|
+
console.info(colors.cyan("https://ptbk.io"));
|
|
329
|
+
process.exit(0);
|
|
330
|
+
return [2 /*return*/];
|
|
331
|
+
});
|
|
332
|
+
}); });
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* TODO: [🗽] Unite branding and make single place for it
|
|
336
|
+
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Initializes testing `hello` command for Promptbook CLI utilities
|
|
341
|
+
*
|
|
342
|
+
* @private internal function of `promptbookCli`
|
|
343
|
+
*/
|
|
344
|
+
function initializeHelloCommand(program) {
|
|
345
|
+
var _this = this;
|
|
346
|
+
var helloCommand = program.command('hello');
|
|
347
|
+
helloCommand.description(spaceTrim("\n Just command for testing\n "));
|
|
348
|
+
helloCommand.argument('[name]', 'Your name', 'Paul');
|
|
349
|
+
helloCommand.option('-g, --greeting <greeting>', "Greeting", 'Hello');
|
|
350
|
+
helloCommand.action(function (name, _a) {
|
|
351
|
+
var greeting = _a.greeting;
|
|
352
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
353
|
+
return __generator(this, function (_b) {
|
|
354
|
+
switch (_b.label) {
|
|
355
|
+
case 0:
|
|
356
|
+
console.info(colors.cyan("".concat(greeting, " ").concat(name)));
|
|
357
|
+
return [4 /*yield*/, forTime(1000)];
|
|
358
|
+
case 1:
|
|
359
|
+
_b.sent();
|
|
360
|
+
console.info(colors.rainbow("Nice to meet you!"));
|
|
361
|
+
process.exit(0);
|
|
362
|
+
return [2 /*return*/];
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
370
|
+
*/
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Converts PipelineCollection to serialized JSON
|
|
374
|
+
*
|
|
375
|
+
* Note: Functions `collectionToJson` and `createCollectionFromJson` are complementary
|
|
376
|
+
*
|
|
377
|
+
* @public exported from `@promptbook/core`
|
|
378
|
+
*/
|
|
379
|
+
function collectionToJson(collection) {
|
|
380
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
381
|
+
var pipelineUrls, promptbooks;
|
|
382
|
+
return __generator(this, function (_a) {
|
|
383
|
+
switch (_a.label) {
|
|
384
|
+
case 0: return [4 /*yield*/, collection.listPipelines()];
|
|
385
|
+
case 1:
|
|
386
|
+
pipelineUrls = _a.sent();
|
|
387
|
+
return [4 /*yield*/, Promise.all(pipelineUrls.map(function (url) { return collection.getPipelineByUrl(url); }))];
|
|
388
|
+
case 2:
|
|
389
|
+
promptbooks = _a.sent();
|
|
390
|
+
return [2 /*return*/, promptbooks];
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* TODO: [🧠] Maybe clear `sourceFile` or clear when exposing through API or remote server
|
|
397
|
+
*/
|
|
398
|
+
|
|
365
399
|
/**
|
|
366
400
|
* Prettify the html code
|
|
367
401
|
*
|
|
@@ -805,7 +839,7 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
805
839
|
});
|
|
806
840
|
}
|
|
807
841
|
|
|
808
|
-
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.63.0-
|
|
842
|
+
var PipelineCollection = [{title:"Prepare Knowledge from Markdown",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-from-markdown.ptbk.md",promptbookVersion:"0.63.0-6",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:[{id:1,promptbookVersion:"0.63.0-6",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-from-markdown.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-keywords.ptbk.md",promptbookVersion:"0.63.0-6",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:[{id:1,promptbookVersion:"0.63.0-6",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-keywords.ptbk.md"},{title:"Prepare Title",pipelineUrl:"https://promptbook.studio/promptbook/prepare-knowledge-title.ptbk.md",promptbookVersion:"0.63.0-6",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:[{id:1,promptbookVersion:"0.63.0-6",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-knowledge-title.ptbk.md"},{title:"Prepare Keywords",pipelineUrl:"https://promptbook.studio/promptbook/prepare-persona.ptbk.md",promptbookVersion:"0.63.0-6",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:[{id:1,promptbookVersion:"0.63.0-6",usage:{price:{value:0},input:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}},output:{tokensCount:{value:0},charactersCount:{value:0},wordsCount:{value:0},sentencesCount:{value:0},linesCount:{value:0},paragraphsCount:{value:0},pagesCount:{value:0}}}}],sourceFile:"./promptbook-collection/prepare-persona.ptbk.md"}];
|
|
809
843
|
|
|
810
844
|
/**
|
|
811
845
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
@@ -5905,6 +5939,75 @@ var CollectionError = /** @class */ (function (_super) {
|
|
|
5905
5939
|
return CollectionError;
|
|
5906
5940
|
}(Error));
|
|
5907
5941
|
|
|
5942
|
+
/**
|
|
5943
|
+
* Checks if the file exists
|
|
5944
|
+
*
|
|
5945
|
+
* @private within the repository
|
|
5946
|
+
*/
|
|
5947
|
+
function isFileExisting(filePath) {
|
|
5948
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5949
|
+
var isReadAccessAllowed, isFile;
|
|
5950
|
+
return __generator(this, function (_a) {
|
|
5951
|
+
switch (_a.label) {
|
|
5952
|
+
case 0: return [4 /*yield*/, access(filePath, constants.R_OK)
|
|
5953
|
+
.then(function () { return true; })
|
|
5954
|
+
.catch(function () { return false; })];
|
|
5955
|
+
case 1:
|
|
5956
|
+
isReadAccessAllowed = _a.sent();
|
|
5957
|
+
if (!isReadAccessAllowed) {
|
|
5958
|
+
return [2 /*return*/, false];
|
|
5959
|
+
}
|
|
5960
|
+
return [4 /*yield*/, stat(filePath)
|
|
5961
|
+
.then(function (fileStat) { return fileStat.isFile(); })
|
|
5962
|
+
.catch(function () { return false; })];
|
|
5963
|
+
case 2:
|
|
5964
|
+
isFile = _a.sent();
|
|
5965
|
+
return [2 /*return*/, isFile];
|
|
5966
|
+
}
|
|
5967
|
+
});
|
|
5968
|
+
});
|
|
5969
|
+
}
|
|
5970
|
+
/**
|
|
5971
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node` and `@promptbook/cli` and `@promptbook/cli`
|
|
5972
|
+
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
5973
|
+
* TODO: [🖇] What about symlinks?
|
|
5974
|
+
*/
|
|
5975
|
+
|
|
5976
|
+
/**
|
|
5977
|
+
* Checks if the directory exists
|
|
5978
|
+
*
|
|
5979
|
+
* @private within the repository
|
|
5980
|
+
*/
|
|
5981
|
+
function isDirectoryExisting(directoryPath) {
|
|
5982
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
5983
|
+
var isReadAccessAllowed, isDirectory;
|
|
5984
|
+
return __generator(this, function (_a) {
|
|
5985
|
+
switch (_a.label) {
|
|
5986
|
+
case 0: return [4 /*yield*/, access(directoryPath, constants.R_OK)
|
|
5987
|
+
.then(function () { return true; })
|
|
5988
|
+
.catch(function () { return false; })];
|
|
5989
|
+
case 1:
|
|
5990
|
+
isReadAccessAllowed = _a.sent();
|
|
5991
|
+
if (!isReadAccessAllowed) {
|
|
5992
|
+
return [2 /*return*/, false];
|
|
5993
|
+
}
|
|
5994
|
+
return [4 /*yield*/, stat(directoryPath)
|
|
5995
|
+
.then(function (fileStat) { return fileStat.isDirectory(); })
|
|
5996
|
+
.catch(function () { return false; })];
|
|
5997
|
+
case 2:
|
|
5998
|
+
isDirectory = _a.sent();
|
|
5999
|
+
return [2 /*return*/, isDirectory];
|
|
6000
|
+
}
|
|
6001
|
+
});
|
|
6002
|
+
});
|
|
6003
|
+
}
|
|
6004
|
+
/**
|
|
6005
|
+
* Note: [🟢] This code should never be published outside of `@promptbook/node` and `@promptbook/cli` and `@promptbook/cli`
|
|
6006
|
+
* TODO: [🐠] This can be a validator - with variants that return true/false and variants that throw errors with meaningless messages
|
|
6007
|
+
* TODO: [🧠][📂] "directory" vs "folder"
|
|
6008
|
+
* TODO: [🖇] What about symlinks?
|
|
6009
|
+
*/
|
|
6010
|
+
|
|
5908
6011
|
/**
|
|
5909
6012
|
* Reads all files in the directory
|
|
5910
6013
|
*
|
|
@@ -5919,53 +6022,60 @@ function listAllFiles(path, isRecursive) {
|
|
|
5919
6022
|
var e_1, _g;
|
|
5920
6023
|
return __generator(this, function (_h) {
|
|
5921
6024
|
switch (_h.label) {
|
|
5922
|
-
case 0: return [4 /*yield*/,
|
|
5923
|
-
withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
|
|
5924
|
-
})];
|
|
6025
|
+
case 0: return [4 /*yield*/, isDirectoryExisting(path)];
|
|
5925
6026
|
case 1:
|
|
6027
|
+
if (!(_h.sent())) {
|
|
6028
|
+
throw new Error("Directory \"".concat(path, "\" does not exist or is not readable"));
|
|
6029
|
+
// <- TODO: Use some custom error class
|
|
6030
|
+
}
|
|
6031
|
+
return [4 /*yield*/, readdir(path, {
|
|
6032
|
+
withFileTypes: true /* Note: This is not working: recursive: isRecursive */,
|
|
6033
|
+
})];
|
|
6034
|
+
case 2:
|
|
5926
6035
|
dirents = _h.sent();
|
|
5927
6036
|
fileNames = dirents.filter(function (dirent) { return dirent.isFile(); }).map(function (_a) {
|
|
5928
6037
|
var name = _a.name;
|
|
5929
6038
|
return join(path, name);
|
|
5930
6039
|
});
|
|
5931
|
-
if (!isRecursive) return [3 /*break*/,
|
|
5932
|
-
_h.label = 2;
|
|
5933
|
-
case 2:
|
|
5934
|
-
_h.trys.push([2, 7, 8, 9]);
|
|
5935
|
-
_a = __values(dirents.filter(function (dirent) { return dirent.isDirectory(); })), _b = _a.next();
|
|
6040
|
+
if (!isRecursive) return [3 /*break*/, 10];
|
|
5936
6041
|
_h.label = 3;
|
|
5937
6042
|
case 3:
|
|
5938
|
-
|
|
6043
|
+
_h.trys.push([3, 8, 9, 10]);
|
|
6044
|
+
_a = __values(dirents.filter(function (dirent) { return dirent.isDirectory(); })), _b = _a.next();
|
|
6045
|
+
_h.label = 4;
|
|
6046
|
+
case 4:
|
|
6047
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
5939
6048
|
dirent = _b.value;
|
|
5940
6049
|
subPath = join(path, dirent.name);
|
|
5941
6050
|
_d = (_c = fileNames.push).apply;
|
|
5942
6051
|
_e = [fileNames];
|
|
5943
6052
|
_f = [[]];
|
|
5944
6053
|
return [4 /*yield*/, listAllFiles(subPath, isRecursive)];
|
|
5945
|
-
case 4:
|
|
5946
|
-
_d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
5947
|
-
_h.label = 5;
|
|
5948
6054
|
case 5:
|
|
6055
|
+
_d.apply(_c, _e.concat([__spreadArray.apply(void 0, _f.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
6056
|
+
_h.label = 6;
|
|
6057
|
+
case 6:
|
|
5949
6058
|
_b = _a.next();
|
|
5950
|
-
return [3 /*break*/,
|
|
5951
|
-
case
|
|
5952
|
-
case
|
|
6059
|
+
return [3 /*break*/, 4];
|
|
6060
|
+
case 7: return [3 /*break*/, 10];
|
|
6061
|
+
case 8:
|
|
5953
6062
|
e_1_1 = _h.sent();
|
|
5954
6063
|
e_1 = { error: e_1_1 };
|
|
5955
|
-
return [3 /*break*/,
|
|
5956
|
-
case
|
|
6064
|
+
return [3 /*break*/, 10];
|
|
6065
|
+
case 9:
|
|
5957
6066
|
try {
|
|
5958
6067
|
if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
|
|
5959
6068
|
}
|
|
5960
6069
|
finally { if (e_1) throw e_1.error; }
|
|
5961
6070
|
return [7 /*endfinally*/];
|
|
5962
|
-
case
|
|
6071
|
+
case 10: return [2 /*return*/, fileNames];
|
|
5963
6072
|
}
|
|
5964
6073
|
});
|
|
5965
6074
|
});
|
|
5966
6075
|
}
|
|
5967
6076
|
/**
|
|
5968
6077
|
* Note: [🟢] This code should never be published outside of `@promptbook/node` and `@promptbook/cli` and `@promptbook/cli`
|
|
6078
|
+
* TODO: [🖇] What about symlinks?
|
|
5969
6079
|
*/
|
|
5970
6080
|
|
|
5971
6081
|
/**
|
|
@@ -6067,7 +6177,7 @@ function createCollectionFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
|
6067
6177
|
*/
|
|
6068
6178
|
function createCollectionFromDirectory(path, options) {
|
|
6069
6179
|
return __awaiter(this, void 0, void 0, function () {
|
|
6070
|
-
var makedLibraryFilePath,
|
|
6180
|
+
var makedLibraryFilePath, _a, _b, isRecursive, _c, isVerbose, _d, isLazyLoaded, _e, isCrashedOnError, collection;
|
|
6071
6181
|
var _this = this;
|
|
6072
6182
|
return __generator(this, function (_f) {
|
|
6073
6183
|
switch (_f.label) {
|
|
@@ -6076,12 +6186,9 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6076
6186
|
throw new Error('Function `createCollectionFromDirectory` can only be run in Node.js environment because it reads the file system.');
|
|
6077
6187
|
}
|
|
6078
6188
|
makedLibraryFilePath = join$1(path, "".concat(PIPELINE_COLLECTION_BASE_FILENAME, ".json"));
|
|
6079
|
-
return [4 /*yield*/,
|
|
6080
|
-
.then(function () { return true; })
|
|
6081
|
-
.catch(function () { return false; })];
|
|
6189
|
+
return [4 /*yield*/, isFileExisting(makedLibraryFilePath)];
|
|
6082
6190
|
case 1:
|
|
6083
|
-
|
|
6084
|
-
if (!makedLibraryFileExists) {
|
|
6191
|
+
if (!(_f.sent())) {
|
|
6085
6192
|
console.info(colors.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.")));
|
|
6086
6193
|
}
|
|
6087
6194
|
else {
|
|
@@ -6245,6 +6352,7 @@ function createCollectionFromDirectory(path, options) {
|
|
|
6245
6352
|
}
|
|
6246
6353
|
/**
|
|
6247
6354
|
* Note: [🟢] This code should never be published outside of `@promptbook/node` and `@promptbook/cli` and `@promptbook/cli`
|
|
6355
|
+
* TODO: [🖇] What about symlinks? Maybe option isSymlinksFollowed
|
|
6248
6356
|
*/
|
|
6249
6357
|
|
|
6250
6358
|
/**
|
|
@@ -6350,17 +6458,14 @@ var FilesStorage = /** @class */ (function () {
|
|
|
6350
6458
|
*/
|
|
6351
6459
|
FilesStorage.prototype.getItem = function (key) {
|
|
6352
6460
|
return __awaiter(this, void 0, void 0, function () {
|
|
6353
|
-
var filename,
|
|
6461
|
+
var filename, fileContent, value;
|
|
6354
6462
|
return __generator(this, function (_a) {
|
|
6355
6463
|
switch (_a.label) {
|
|
6356
6464
|
case 0:
|
|
6357
6465
|
filename = this.getFilenameForKey(key);
|
|
6358
|
-
return [4 /*yield*/,
|
|
6359
|
-
.then(function (fileStat) { return fileStat.isFile(); })
|
|
6360
|
-
.catch(function () { return false; })];
|
|
6466
|
+
return [4 /*yield*/, isFileExisting(filename)];
|
|
6361
6467
|
case 1:
|
|
6362
|
-
|
|
6363
|
-
if (!isFileExisting) {
|
|
6468
|
+
if (!(_a.sent())) {
|
|
6364
6469
|
return [2 /*return*/, null];
|
|
6365
6470
|
}
|
|
6366
6471
|
return [4 /*yield*/, readFile(filename, 'utf-8')];
|
|
@@ -7717,8 +7822,10 @@ function initializeMakeCommand(program) {
|
|
|
7717
7822
|
var _this = this;
|
|
7718
7823
|
var makeCommand = program.command('make');
|
|
7719
7824
|
makeCommand.description(spaceTrim("\n Makes a new pipeline collection in given folder\n "));
|
|
7720
|
-
makeCommand.argument('
|
|
7721
|
-
|
|
7825
|
+
makeCommand.argument('[path]',
|
|
7826
|
+
// <- TODO: [🧟♂️] Unite path to promptbook collection argument
|
|
7827
|
+
'Path to promptbook directory', './promptbook-collection');
|
|
7828
|
+
makeCommand.option('--project-name', "Name of the project for whom collection is", 'Untitled Promptbook project');
|
|
7722
7829
|
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: [🏳🌈] */);
|
|
7723
7830
|
makeCommand.option('--no-validation', "Do not validate logic of pipelines in collection", true);
|
|
7724
7831
|
makeCommand.option('--validation', "Types of validations separated by comma (options \"logic\",\"imports\")", 'logic,imports');
|
|
@@ -7728,7 +7835,7 @@ function initializeMakeCommand(program) {
|
|
|
7728
7835
|
makeCommand.action(function (path, _a) {
|
|
7729
7836
|
var projectName = _a.projectName, format = _a.format, validation = _a.validation, reloadCache = _a.reloadCache, verbose = _a.verbose, outFile = _a.outFile;
|
|
7730
7837
|
return __awaiter(_this, void 0, void 0, function () {
|
|
7731
|
-
var isCacheReloaded, isVerbose, formats, validations, llmTools, collection, validations_1, validations_1_1, validation_1, _b, _c, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, saveFile;
|
|
7838
|
+
var isCacheReloaded, isVerbose, formats, validations, llmTools, collection, validations_1, validations_1_1, validation_1, _b, _c, pipelineUrl, pipeline, e_1_1, e_2_1, collectionJson, collectionJsonString, collectionJsonItems, saveFile;
|
|
7732
7839
|
var e_2, _d, e_1, _e;
|
|
7733
7840
|
var _this = this;
|
|
7734
7841
|
return __generator(this, function (_f) {
|
|
@@ -7745,7 +7852,7 @@ function initializeMakeCommand(program) {
|
|
|
7745
7852
|
.map(function (_) { return _.trim(); })
|
|
7746
7853
|
.filter(function (_) { return _ !== ''; });
|
|
7747
7854
|
if (outFile !== PIPELINE_COLLECTION_BASE_FILENAME && formats.length !== 1) {
|
|
7748
|
-
console.error(colors.red("You can use
|
|
7855
|
+
console.error(colors.red("You can only use one format if you specify --out-file"));
|
|
7749
7856
|
process.exit(1);
|
|
7750
7857
|
}
|
|
7751
7858
|
llmTools = getLlmToolsForCli({
|
|
@@ -7819,7 +7926,16 @@ function initializeMakeCommand(program) {
|
|
|
7819
7926
|
case 16: return [4 /*yield*/, collectionToJson(collection)];
|
|
7820
7927
|
case 17:
|
|
7821
7928
|
collectionJson = _f.sent();
|
|
7822
|
-
collectionJsonString = stringifyPipelineJson(collectionJson);
|
|
7929
|
+
collectionJsonString = stringifyPipelineJson(collectionJson).trim();
|
|
7930
|
+
collectionJsonItems = (function () {
|
|
7931
|
+
if (collectionJsonString.substring(0, 1) !== '{') {
|
|
7932
|
+
throw new UnexpectedError('Missing { at the beginning of serialized collection');
|
|
7933
|
+
}
|
|
7934
|
+
if (collectionJsonString.substring(-1) !== '}') {
|
|
7935
|
+
throw new UnexpectedError('Missing } at the end of serialized collection');
|
|
7936
|
+
}
|
|
7937
|
+
return spaceTrim(collectionJsonString.substring(1, collectionJsonString.length - 1));
|
|
7938
|
+
})();
|
|
7823
7939
|
saveFile = function (extension, content) { return __awaiter(_this, void 0, void 0, function () {
|
|
7824
7940
|
var filePath;
|
|
7825
7941
|
return __generator(this, function (_a) {
|
|
@@ -7852,18 +7968,14 @@ function initializeMakeCommand(program) {
|
|
|
7852
7968
|
case 19:
|
|
7853
7969
|
if (!(formats.includes('javascript') || formats.includes('js'))) return [3 /*break*/, 21];
|
|
7854
7970
|
formats = formats.filter(function (format) { return format !== 'javascript' && format !== 'js'; });
|
|
7855
|
-
return [4 /*yield*/, saveFile('js', spaceTrim(function (block) {
|
|
7856
|
-
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(").concat(collectionJsonString.substring(1, collectionJsonString.length - 1), ");\n }\n\n return pipelineCollection;\n }\n ") + '\n';
|
|
7857
|
-
}))];
|
|
7971
|
+
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 "); }))];
|
|
7858
7972
|
case 20:
|
|
7859
|
-
_f.sent();
|
|
7973
|
+
(_f.sent()) + '\n';
|
|
7860
7974
|
_f.label = 21;
|
|
7861
7975
|
case 21:
|
|
7862
7976
|
if (!(formats.includes('typescript') || formats.includes('ts'))) return [3 /*break*/, 23];
|
|
7863
7977
|
formats = formats.filter(function (format) { return format !== 'typescript' && format !== 'ts'; });
|
|
7864
|
-
return [4 /*yield*/, saveFile('ts', spaceTrim(function (block) {
|
|
7865
|
-
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(").concat(collectionJsonString.substring(1, collectionJsonString.length - 1), ");\n }\n\n return pipelineCollection as PipelineCollection;\n }\n ") + '\n';
|
|
7866
|
-
}))];
|
|
7978
|
+
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')];
|
|
7867
7979
|
case 22:
|
|
7868
7980
|
_f.sent();
|
|
7869
7981
|
_f.label = 23;
|
|
@@ -7883,7 +7995,10 @@ function initializeMakeCommand(program) {
|
|
|
7883
7995
|
});
|
|
7884
7996
|
}
|
|
7885
7997
|
/**
|
|
7998
|
+
* TODO: Maybe remove this command - "about" command should be enough?
|
|
7999
|
+
* TODO: [0] DRY Javascript and typescript - Maybe make ONLY typescript and for javascript just remove types
|
|
7886
8000
|
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
8001
|
+
* TODO: [🖇] What about symlinks? Maybe flag --follow-symlinks
|
|
7887
8002
|
*/
|
|
7888
8003
|
|
|
7889
8004
|
/**
|
|
@@ -8087,7 +8202,9 @@ function initializePrettifyCommand(program) {
|
|
|
8087
8202
|
var _this = this;
|
|
8088
8203
|
var prettifyCommand = program.command('prettify');
|
|
8089
8204
|
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 "));
|
|
8090
|
-
prettifyCommand.argument('<filesGlob>',
|
|
8205
|
+
prettifyCommand.argument('<filesGlob>',
|
|
8206
|
+
// <- TODO: [🧟♂️] Unite path to promptbook collection argument
|
|
8207
|
+
'Promptbooks to prettify as glob pattern');
|
|
8091
8208
|
prettifyCommand.option('-i, --ignore <glob>', "Ignore as glob pattern");
|
|
8092
8209
|
prettifyCommand.action(function (filesGlob, _a) {
|
|
8093
8210
|
var ignore = _a.ignore;
|
|
@@ -8163,6 +8280,7 @@ function initializePrettifyCommand(program) {
|
|
|
8163
8280
|
}
|
|
8164
8281
|
/**
|
|
8165
8282
|
* Note: [🟡] This code should never be published outside of `@promptbook/cli`
|
|
8283
|
+
* TODO: [🖇] What about symlinks? Maybe flag --follow-symlinks
|
|
8166
8284
|
*/
|
|
8167
8285
|
|
|
8168
8286
|
/**
|
|
@@ -8179,8 +8297,10 @@ function promptbookCli() {
|
|
|
8179
8297
|
}
|
|
8180
8298
|
program = new commander.Command();
|
|
8181
8299
|
program.name('promptbook');
|
|
8300
|
+
program.alias('ptbk');
|
|
8182
8301
|
program.version(PROMPTBOOK_VERSION);
|
|
8183
8302
|
program.description(spaceTrim$1("\n Promptbook utilities for enhancing workflow with promptbooks\n "));
|
|
8303
|
+
initializeAboutCommand(program);
|
|
8184
8304
|
initializeHelloCommand(program);
|
|
8185
8305
|
initializeMakeCommand(program);
|
|
8186
8306
|
initializePrettifyCommand(program);
|