@promptbook/markdown-utils 0.80.0-1 → 0.81.0-5
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/README.md +2 -0
- package/esm/index.es.js +38 -13
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +0 -6
- package/esm/typings/src/_packages/editable.index.d.ts +10 -0
- package/esm/typings/src/_packages/templates.index.d.ts +4 -0
- package/esm/typings/src/_packages/types.index.d.ts +4 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -2
- package/esm/typings/src/execution/ExecutionTools.d.ts +7 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +5 -0
- package/esm/typings/src/execution/PromptbookFetch.test-type.d.ts +5 -0
- package/esm/typings/src/expectations/drafts/isDomainNameFree.d.ts +2 -1
- package/esm/typings/src/expectations/drafts/isGithubNameFree.d.ts +2 -1
- package/esm/typings/src/scrapers/_common/utils/makeKnowledgeSourceHandler.d.ts +1 -1
- package/esm/typings/src/scrapers/_common/utils/scraperFetch.d.ts +7 -0
- package/esm/typings/src/utils/editable/types/PipelineEditableSerialized.d.ts +42 -0
- package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.d.ts +3 -3
- package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.d.ts +3 -3
- package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.d.ts +2 -2
- package/esm/typings/src/utils/getBookTemplate.d.ts +12 -0
- package/esm/typings/src/utils/parameters/{replaceParameters.d.ts → templateParameters.d.ts} +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +38 -13
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/{conversion → utils/editable}/utils/removePipelineCommand.test.d.ts +0 -0
- /package/esm/typings/src/{conversion → utils/editable}/utils/renamePipelineParameter.test.d.ts +0 -0
- /package/esm/typings/src/{conversion → utils/editable}/utils/stringifyPipelineJson.test.d.ts +0 -0
- /package/esm/typings/src/utils/parameters/{replaceParameters.test.d.ts → templateParameters.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -251,6 +251,8 @@ Or you can install them separately:
|
|
|
251
251
|
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
|
|
252
252
|
- **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
|
|
253
253
|
- **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
|
|
254
|
+
- **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
|
|
255
|
+
- **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
|
|
254
256
|
- **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
|
|
255
257
|
- **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
|
|
256
258
|
|
package/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
20
20
|
*
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
23
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-4';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
26
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -3400,6 +3400,30 @@ function isValidFilePath(filename) {
|
|
|
3400
3400
|
return false;
|
|
3401
3401
|
}
|
|
3402
3402
|
|
|
3403
|
+
/**
|
|
3404
|
+
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3405
|
+
*
|
|
3406
|
+
* @private as default `fetch` function used in Promptbook scrapers
|
|
3407
|
+
*/
|
|
3408
|
+
var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3409
|
+
var error_1;
|
|
3410
|
+
return __generator(this, function (_a) {
|
|
3411
|
+
switch (_a.label) {
|
|
3412
|
+
case 0:
|
|
3413
|
+
_a.trys.push([0, 2, , 3]);
|
|
3414
|
+
return [4 /*yield*/, fetch(url, init)];
|
|
3415
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
3416
|
+
case 2:
|
|
3417
|
+
error_1 = _a.sent();
|
|
3418
|
+
if (!(error_1 instanceof Error)) {
|
|
3419
|
+
throw error_1;
|
|
3420
|
+
}
|
|
3421
|
+
throw new KnowledgeScrapeError(spaceTrim(function (block) { return "\n Can not fetch \"".concat(url, "\"\n\n Fetch error:\n ").concat(block(error_1.message), "\n\n "); }));
|
|
3422
|
+
case 3: return [2 /*return*/];
|
|
3423
|
+
}
|
|
3424
|
+
});
|
|
3425
|
+
}); };
|
|
3426
|
+
|
|
3403
3427
|
/**
|
|
3404
3428
|
* @@@
|
|
3405
3429
|
*
|
|
@@ -3408,13 +3432,14 @@ function isValidFilePath(filename) {
|
|
|
3408
3432
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3409
3433
|
var _a;
|
|
3410
3434
|
return __awaiter(this, void 0, void 0, function () {
|
|
3411
|
-
var sourceContent, name,
|
|
3412
|
-
return __generator(this, function (
|
|
3413
|
-
switch (
|
|
3435
|
+
var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
3436
|
+
return __generator(this, function (_f) {
|
|
3437
|
+
switch (_f.label) {
|
|
3414
3438
|
case 0:
|
|
3439
|
+
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
3415
3440
|
sourceContent = knowledgeSource.sourceContent;
|
|
3416
3441
|
name = knowledgeSource.name;
|
|
3417
|
-
|
|
3442
|
+
_c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
|
|
3418
3443
|
if (!name) {
|
|
3419
3444
|
name = sourceContentToName(sourceContent);
|
|
3420
3445
|
}
|
|
@@ -3422,7 +3447,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3422
3447
|
url = sourceContent;
|
|
3423
3448
|
return [4 /*yield*/, fetch(url)];
|
|
3424
3449
|
case 1:
|
|
3425
|
-
response_1 =
|
|
3450
|
+
response_1 = _f.sent();
|
|
3426
3451
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
3427
3452
|
return [2 /*return*/, {
|
|
3428
3453
|
source: name,
|
|
@@ -3479,7 +3504,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3479
3504
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
3480
3505
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
3481
3506
|
case 3:
|
|
3482
|
-
if (!(
|
|
3507
|
+
if (!(_f.sent())) {
|
|
3483
3508
|
throw new NotFoundError(spaceTrim(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
|
|
3484
3509
|
}
|
|
3485
3510
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -4379,7 +4404,7 @@ function mapAvailableToExpectedParameters(options) {
|
|
|
4379
4404
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
4380
4405
|
* @public exported from `@promptbook/utils`
|
|
4381
4406
|
*/
|
|
4382
|
-
function
|
|
4407
|
+
function templateParameters(template, parameters) {
|
|
4383
4408
|
var e_1, _a;
|
|
4384
4409
|
try {
|
|
4385
4410
|
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -4405,7 +4430,7 @@ function replaceParameters(template, parameters) {
|
|
|
4405
4430
|
var loopLimit = LOOP_LIMIT;
|
|
4406
4431
|
var _loop_1 = function () {
|
|
4407
4432
|
if (loopLimit-- < 0) {
|
|
4408
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `
|
|
4433
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
4409
4434
|
}
|
|
4410
4435
|
var precol = match.groups.precol;
|
|
4411
4436
|
var parameterName = match.groups.parameterName;
|
|
@@ -4657,7 +4682,7 @@ function executeAttempts(options) {
|
|
|
4657
4682
|
}
|
|
4658
4683
|
return [3 /*break*/, 24];
|
|
4659
4684
|
case 2:
|
|
4660
|
-
$ongoingTaskResult.$resultString =
|
|
4685
|
+
$ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
|
|
4661
4686
|
return [3 /*break*/, 25];
|
|
4662
4687
|
case 3:
|
|
4663
4688
|
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
@@ -4780,8 +4805,8 @@ function executeAttempts(options) {
|
|
|
4780
4805
|
_j = $ongoingTaskResult;
|
|
4781
4806
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
4782
4807
|
promptTitle: task.title,
|
|
4783
|
-
promptMessage:
|
|
4784
|
-
defaultValue:
|
|
4808
|
+
promptMessage: templateParameters(task.description || '', parameters),
|
|
4809
|
+
defaultValue: templateParameters(preparedContent, parameters),
|
|
4785
4810
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
4786
4811
|
placeholder: undefined,
|
|
4787
4812
|
priority: priority,
|
|
@@ -4905,7 +4930,7 @@ function executeAttempts(options) {
|
|
|
4905
4930
|
if (!isJokerAttempt &&
|
|
4906
4931
|
task.taskType === 'PROMPT_TASK' &&
|
|
4907
4932
|
$ongoingTaskResult.$prompt
|
|
4908
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in
|
|
4933
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
|
|
4909
4934
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
4910
4935
|
) {
|
|
4911
4936
|
// TODO: [🧠] Maybe put other taskTypes into report
|