@promptbook/node 0.80.0 → 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 +6 -0
- package/esm/index.es.js +39 -14
- 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 +2 -2
- package/umd/index.umd.js +39 -14
- 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
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
<blockquote style="color: #ff8811">
|
|
27
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
+
</blockquote>
|
|
29
|
+
|
|
26
30
|
## 📦 Package `@promptbook/node`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -251,6 +255,8 @@ Or you can install them separately:
|
|
|
251
255
|
- **[@promptbook/documents](https://www.npmjs.com/package/@promptbook/documents)** - Read knowledge from documents like `.docx`, `.odt`,…
|
|
252
256
|
- **[@promptbook/legacy-documents](https://www.npmjs.com/package/@promptbook/legacy-documents)** - Read knowledge from legacy documents like `.doc`, `.rtf`,…
|
|
253
257
|
- **[@promptbook/website-crawler](https://www.npmjs.com/package/@promptbook/website-crawler)** - Crawl knowledge from the web
|
|
258
|
+
- **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
|
|
259
|
+
- **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
|
|
254
260
|
- **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
|
|
255
261
|
- **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
|
|
256
262
|
|
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
*
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.
|
|
29
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.81.0-4';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -3135,7 +3135,7 @@ function arrayableToArray(input) {
|
|
|
3135
3135
|
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
3136
3136
|
* @public exported from `@promptbook/utils`
|
|
3137
3137
|
*/
|
|
3138
|
-
function
|
|
3138
|
+
function templateParameters(template, parameters) {
|
|
3139
3139
|
var e_1, _a;
|
|
3140
3140
|
try {
|
|
3141
3141
|
for (var _b = __values(Object.entries(parameters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -3161,7 +3161,7 @@ function replaceParameters(template, parameters) {
|
|
|
3161
3161
|
var loopLimit = LOOP_LIMIT;
|
|
3162
3162
|
var _loop_1 = function () {
|
|
3163
3163
|
if (loopLimit-- < 0) {
|
|
3164
|
-
throw new LimitReachedError('Loop limit reached during parameters replacement in `
|
|
3164
|
+
throw new LimitReachedError('Loop limit reached during parameters replacement in `templateParameters`');
|
|
3165
3165
|
}
|
|
3166
3166
|
var precol = match.groups.precol;
|
|
3167
3167
|
var parameterName = match.groups.parameterName;
|
|
@@ -3674,7 +3674,7 @@ function executeAttempts(options) {
|
|
|
3674
3674
|
}
|
|
3675
3675
|
return [3 /*break*/, 24];
|
|
3676
3676
|
case 2:
|
|
3677
|
-
$ongoingTaskResult.$resultString =
|
|
3677
|
+
$ongoingTaskResult.$resultString = templateParameters(preparedContent, parameters);
|
|
3678
3678
|
return [3 /*break*/, 25];
|
|
3679
3679
|
case 3:
|
|
3680
3680
|
modelRequirements = __assign(__assign({ modelVariant: 'CHAT' }, (preparedPipeline.defaultModelRequirements || {})), (task.modelRequirements || {}));
|
|
@@ -3797,8 +3797,8 @@ function executeAttempts(options) {
|
|
|
3797
3797
|
_j = $ongoingTaskResult;
|
|
3798
3798
|
return [4 /*yield*/, tools.userInterface.promptDialog($deepFreeze({
|
|
3799
3799
|
promptTitle: task.title,
|
|
3800
|
-
promptMessage:
|
|
3801
|
-
defaultValue:
|
|
3800
|
+
promptMessage: templateParameters(task.description || '', parameters),
|
|
3801
|
+
defaultValue: templateParameters(preparedContent, parameters),
|
|
3802
3802
|
// TODO: [🧠] !! Figure out how to define placeholder in .book.md file
|
|
3803
3803
|
placeholder: undefined,
|
|
3804
3804
|
priority: priority,
|
|
@@ -3922,7 +3922,7 @@ function executeAttempts(options) {
|
|
|
3922
3922
|
if (!isJokerAttempt &&
|
|
3923
3923
|
task.taskType === 'PROMPT_TASK' &&
|
|
3924
3924
|
$ongoingTaskResult.$prompt
|
|
3925
|
-
// <- Note: [2] When some expected parameter is not defined, error will occur in
|
|
3925
|
+
// <- Note: [2] When some expected parameter is not defined, error will occur in templateParameters
|
|
3926
3926
|
// In that case we don’t want to make a report about it because it’s not a llm execution error
|
|
3927
3927
|
) {
|
|
3928
3928
|
// TODO: [🧠] Maybe put other taskTypes into report
|
|
@@ -5249,6 +5249,30 @@ function isValidFilePath(filename) {
|
|
|
5249
5249
|
return false;
|
|
5250
5250
|
}
|
|
5251
5251
|
|
|
5252
|
+
/**
|
|
5253
|
+
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5254
|
+
*
|
|
5255
|
+
* @private as default `fetch` function used in Promptbook scrapers
|
|
5256
|
+
*/
|
|
5257
|
+
var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
5258
|
+
var error_1;
|
|
5259
|
+
return __generator(this, function (_a) {
|
|
5260
|
+
switch (_a.label) {
|
|
5261
|
+
case 0:
|
|
5262
|
+
_a.trys.push([0, 2, , 3]);
|
|
5263
|
+
return [4 /*yield*/, fetch(url, init)];
|
|
5264
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5265
|
+
case 2:
|
|
5266
|
+
error_1 = _a.sent();
|
|
5267
|
+
if (!(error_1 instanceof Error)) {
|
|
5268
|
+
throw error_1;
|
|
5269
|
+
}
|
|
5270
|
+
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 "); }));
|
|
5271
|
+
case 3: return [2 /*return*/];
|
|
5272
|
+
}
|
|
5273
|
+
});
|
|
5274
|
+
}); };
|
|
5275
|
+
|
|
5252
5276
|
/**
|
|
5253
5277
|
* @@@
|
|
5254
5278
|
*
|
|
@@ -5257,13 +5281,14 @@ function isValidFilePath(filename) {
|
|
|
5257
5281
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5258
5282
|
var _a;
|
|
5259
5283
|
return __awaiter(this, void 0, void 0, function () {
|
|
5260
|
-
var sourceContent, name,
|
|
5261
|
-
return __generator(this, function (
|
|
5262
|
-
switch (
|
|
5284
|
+
var _b, fetch, sourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
5285
|
+
return __generator(this, function (_f) {
|
|
5286
|
+
switch (_f.label) {
|
|
5263
5287
|
case 0:
|
|
5288
|
+
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
5264
5289
|
sourceContent = knowledgeSource.sourceContent;
|
|
5265
5290
|
name = knowledgeSource.name;
|
|
5266
|
-
|
|
5291
|
+
_c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
|
|
5267
5292
|
if (!name) {
|
|
5268
5293
|
name = sourceContentToName(sourceContent);
|
|
5269
5294
|
}
|
|
@@ -5271,7 +5296,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5271
5296
|
url = sourceContent;
|
|
5272
5297
|
return [4 /*yield*/, fetch(url)];
|
|
5273
5298
|
case 1:
|
|
5274
|
-
response_1 =
|
|
5299
|
+
response_1 = _f.sent();
|
|
5275
5300
|
mimeType = ((_a = response_1.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
|
|
5276
5301
|
return [2 /*return*/, {
|
|
5277
5302
|
source: name,
|
|
@@ -5328,7 +5353,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
5328
5353
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
5329
5354
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
5330
5355
|
case 3:
|
|
5331
|
-
if (!(
|
|
5356
|
+
if (!(_f.sent())) {
|
|
5332
5357
|
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 "); }));
|
|
5333
5358
|
}
|
|
5334
5359
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
@@ -10691,7 +10716,7 @@ function isSerializableAsJson(value) {
|
|
|
10691
10716
|
* Note: [0] It can be used for more JSON types like whole collection of pipelines, single knowledge piece, etc.
|
|
10692
10717
|
* Note: In contrast to JSON.stringify, this function ensures that **embedding index** is on single line
|
|
10693
10718
|
*
|
|
10694
|
-
* @public exported from `@promptbook/
|
|
10719
|
+
* @public exported from `@promptbook/editable`
|
|
10695
10720
|
*/
|
|
10696
10721
|
function stringifyPipelineJson(pipeline) {
|
|
10697
10722
|
if (!isSerializableAsJson(pipeline)) {
|