@promptbook/core 0.82.0 → 0.83.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/esm/index.es.js +47 -44
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/editable.index.d.ts +74 -0
- package/esm/typings/src/_packages/types.index.d.ts +26 -0
- package/esm/typings/src/commands/BOOK_VERSION/BookVersionCommand.d.ts +1 -1
- package/esm/typings/src/commands/BOOK_VERSION/bookVersionCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/ForeachCommand.d.ts +1 -1
- package/esm/typings/src/commands/FOREACH/foreachCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/FORMAT/formatCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/FORMFACTOR/FormfactorCommand.d.ts +1 -1
- package/esm/typings/src/commands/FORMFACTOR/formfactorCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/JOKER/JokerCommand.d.ts +1 -1
- package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +2 -2
- package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/KNOWLEDGE/utils/{sourceContentToName.d.ts → knowledgeSourceContentToName.d.ts} +2 -2
- package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +2 -1
- package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +2 -1
- package/esm/typings/src/commands/PARAMETER/ParameterCommand.d.ts +1 -1
- package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +1 -1
- package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/POSTPROCESS/PostprocessCommand.d.ts +1 -1
- package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/SECTION/SectionCommand.d.ts +1 -1
- package/esm/typings/src/commands/SECTION/sectionCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/URL/UrlCommand.d.ts +1 -1
- package/esm/typings/src/commands/URL/urlCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/X_ACTION/ActionCommand.d.ts +1 -1
- package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/X_INSTRUMENT/InstrumentCommand.d.ts +1 -1
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +1 -1
- package/esm/typings/src/commands/_common/getParserForCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/parseCommand.d.ts +1 -1
- package/esm/typings/src/commands/_common/stringifyCommand.d.ts +1 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +8 -0
- package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +2 -0
- package/esm/typings/src/commands/index.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineJson/KnowledgeSourceJson.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +47 -44
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/commands/KNOWLEDGE/utils/{sourceContentToName.test.d.ts → knowledgeSourceContentToName.test.d.ts} +0 -0
package/umd/index.umd.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* @generated
|
|
28
28
|
* @see https://github.com/webgptorg/promptbook
|
|
29
29
|
*/
|
|
30
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.82.0
|
|
30
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.82.0';
|
|
31
31
|
/**
|
|
32
32
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
33
33
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -5644,15 +5644,15 @@
|
|
|
5644
5644
|
/**
|
|
5645
5645
|
* Creates unique name for the source
|
|
5646
5646
|
*
|
|
5647
|
-
* @
|
|
5647
|
+
* @public exported from `@promptbook/editable`
|
|
5648
5648
|
*/
|
|
5649
|
-
function
|
|
5650
|
-
var hash = cryptoJs.SHA256(hexEncoder__default["default"].parse(JSON.stringify(
|
|
5649
|
+
function knowledgeSourceContentToName(knowledgeSourceContent) {
|
|
5650
|
+
var hash = cryptoJs.SHA256(hexEncoder__default["default"].parse(JSON.stringify(knowledgeSourceContent)))
|
|
5651
5651
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
5652
5652
|
.toString( /* hex */)
|
|
5653
5653
|
.substring(0, 20);
|
|
5654
5654
|
// <- TODO: [🥬] Make some system for hashes and ids of promptbook
|
|
5655
|
-
var semanticName = normalizeToKebabCase(
|
|
5655
|
+
var semanticName = normalizeToKebabCase(knowledgeSourceContent.substring(0, 20));
|
|
5656
5656
|
var pieces = ['source', semanticName, hash].filter(function (piece) { return piece !== ''; });
|
|
5657
5657
|
var name = pieces.join('-').split('--').join('-');
|
|
5658
5658
|
// <- TODO: Use MAX_FILENAME_LENGTH
|
|
@@ -5801,19 +5801,19 @@
|
|
|
5801
5801
|
function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5802
5802
|
var _a;
|
|
5803
5803
|
return __awaiter(this, void 0, void 0, function () {
|
|
5804
|
-
var _b, fetch,
|
|
5804
|
+
var _b, fetch, knowledgeSourceContent, name, _c, _d, rootDirname, url, response_1, mimeType, filename_1, fileExtension, mimeType;
|
|
5805
5805
|
return __generator(this, function (_f) {
|
|
5806
5806
|
switch (_f.label) {
|
|
5807
5807
|
case 0:
|
|
5808
5808
|
_b = tools.fetch, fetch = _b === void 0 ? scraperFetch : _b;
|
|
5809
|
-
|
|
5809
|
+
knowledgeSourceContent = knowledgeSource.knowledgeSourceContent;
|
|
5810
5810
|
name = knowledgeSource.name;
|
|
5811
5811
|
_c = options || {}, _d = _c.rootDirname, rootDirname = _d === void 0 ? null : _d, _c.isVerbose;
|
|
5812
5812
|
if (!name) {
|
|
5813
|
-
name =
|
|
5813
|
+
name = knowledgeSourceContentToName(knowledgeSourceContent);
|
|
5814
5814
|
}
|
|
5815
|
-
if (!isValidUrl(
|
|
5816
|
-
url =
|
|
5815
|
+
if (!isValidUrl(knowledgeSourceContent)) return [3 /*break*/, 2];
|
|
5816
|
+
url = knowledgeSourceContent;
|
|
5817
5817
|
return [4 /*yield*/, fetch(url)];
|
|
5818
5818
|
case 1:
|
|
5819
5819
|
response_1 = _f.sent();
|
|
@@ -5859,7 +5859,7 @@
|
|
|
5859
5859
|
},
|
|
5860
5860
|
}];
|
|
5861
5861
|
case 2:
|
|
5862
|
-
if (!isValidFilePath(
|
|
5862
|
+
if (!isValidFilePath(knowledgeSourceContent)) return [3 /*break*/, 4];
|
|
5863
5863
|
if (tools.fs === undefined) {
|
|
5864
5864
|
throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
|
|
5865
5865
|
// <- TODO: [🧠] What is the best error type here`
|
|
@@ -5868,13 +5868,13 @@
|
|
|
5868
5868
|
throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
|
|
5869
5869
|
// <- TODO: [🧠] What is the best error type here`
|
|
5870
5870
|
}
|
|
5871
|
-
filename_1 = path.join(rootDirname,
|
|
5871
|
+
filename_1 = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
|
|
5872
5872
|
fileExtension = getFileExtension(filename_1);
|
|
5873
5873
|
mimeType = extensionToMimeType(fileExtension || '');
|
|
5874
5874
|
return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
|
|
5875
5875
|
case 3:
|
|
5876
5876
|
if (!(_f.sent())) {
|
|
5877
|
-
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(
|
|
5877
|
+
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(knowledgeSourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
|
|
5878
5878
|
}
|
|
5879
5879
|
// TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
|
|
5880
5880
|
return [2 /*return*/, {
|
|
@@ -5925,7 +5925,7 @@
|
|
|
5925
5925
|
url: null,
|
|
5926
5926
|
mimeType: 'text/markdown',
|
|
5927
5927
|
asText: function () {
|
|
5928
|
-
return knowledgeSource.
|
|
5928
|
+
return knowledgeSource.knowledgeSourceContent;
|
|
5929
5929
|
},
|
|
5930
5930
|
asJson: function () {
|
|
5931
5931
|
throw new UnexpectedError('Did not expect that `markdownScraper` would need to get the content `asJson`');
|
|
@@ -5987,7 +5987,7 @@
|
|
|
5987
5987
|
partialPieces = __spreadArray([], __read(partialPiecesUnchecked), false);
|
|
5988
5988
|
return [2 /*return*/, "break"];
|
|
5989
5989
|
}
|
|
5990
|
-
console.warn(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n\n The source:\n ").concat(block(knowledgeSource.
|
|
5990
|
+
console.warn(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge from source despite the scraper `".concat(scraper.metadata.className, "` supports the mime type \"").concat(sourceHandler.mimeType, "\".\n\n The source:\n ").concat(block(knowledgeSource.knowledgeSourceContent
|
|
5991
5991
|
.split('\n')
|
|
5992
5992
|
.map(function (line) { return "> ".concat(line); })
|
|
5993
5993
|
.join('\n')), "\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -6025,7 +6025,7 @@
|
|
|
6025
6025
|
return [7 /*endfinally*/];
|
|
6026
6026
|
case 9:
|
|
6027
6027
|
if (partialPieces === null) {
|
|
6028
|
-
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.
|
|
6028
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"](function (block) { return "\n Cannot scrape knowledge\n\n The source:\n > ".concat(block(knowledgeSource.knowledgeSourceContent
|
|
6029
6029
|
.split('\n')
|
|
6030
6030
|
.map(function (line) { return "> ".concat(line); })
|
|
6031
6031
|
.join('\n')), "\n\n No scraper found for the mime type \"").concat(sourceHandler.mimeType, "\"\n\n ").concat(block($registeredScrapersMessage(scrapers)), "\n\n\n "); }));
|
|
@@ -6296,7 +6296,7 @@
|
|
|
6296
6296
|
* Parses the knowledge command
|
|
6297
6297
|
*
|
|
6298
6298
|
* @see `documentationUrl` for more details
|
|
6299
|
-
* @
|
|
6299
|
+
* @public exported from `@promptbook/editable`
|
|
6300
6300
|
*/
|
|
6301
6301
|
var knowledgeCommandParser = {
|
|
6302
6302
|
/**
|
|
@@ -6332,23 +6332,25 @@
|
|
|
6332
6332
|
*/
|
|
6333
6333
|
parse: function (input) {
|
|
6334
6334
|
var args = input.args;
|
|
6335
|
-
var
|
|
6336
|
-
if (
|
|
6335
|
+
var knowledgeSourceContent = spaceTrim__default["default"](args[0] || '');
|
|
6336
|
+
if (knowledgeSourceContent === '') {
|
|
6337
6337
|
throw new ParseError("Source is not defined");
|
|
6338
6338
|
}
|
|
6339
6339
|
// TODO: [main] !!4 Following checks should be applied every link in the `sourceContent`
|
|
6340
|
-
if (
|
|
6340
|
+
if (knowledgeSourceContent.startsWith('http://')) {
|
|
6341
6341
|
throw new ParseError("Source is not secure");
|
|
6342
6342
|
}
|
|
6343
|
-
if (!(isValidFilePath(
|
|
6343
|
+
if (!(isValidFilePath(knowledgeSourceContent) || isValidUrl(knowledgeSourceContent))) {
|
|
6344
6344
|
throw new ParseError("Source not valid");
|
|
6345
6345
|
}
|
|
6346
|
-
if (
|
|
6346
|
+
if (knowledgeSourceContent.startsWith('../') ||
|
|
6347
|
+
knowledgeSourceContent.startsWith('/') ||
|
|
6348
|
+
/^[A-Z]:[\\/]+/i.test(knowledgeSourceContent)) {
|
|
6347
6349
|
throw new ParseError("Source cannot be outside of the .book.md folder");
|
|
6348
6350
|
}
|
|
6349
6351
|
return {
|
|
6350
6352
|
type: 'KNOWLEDGE',
|
|
6351
|
-
|
|
6353
|
+
knowledgeSourceContent: knowledgeSourceContent,
|
|
6352
6354
|
};
|
|
6353
6355
|
},
|
|
6354
6356
|
/**
|
|
@@ -6357,10 +6359,10 @@
|
|
|
6357
6359
|
* Note: `$` is used to indicate that this function mutates given `pipelineJson`
|
|
6358
6360
|
*/
|
|
6359
6361
|
$applyToPipelineJson: function (command, $pipelineJson) {
|
|
6360
|
-
var
|
|
6362
|
+
var knowledgeSourceContent = command.knowledgeSourceContent;
|
|
6361
6363
|
$pipelineJson.knowledgeSources.push({
|
|
6362
|
-
name:
|
|
6363
|
-
|
|
6364
|
+
name: knowledgeSourceContentToName(knowledgeSourceContent),
|
|
6365
|
+
knowledgeSourceContent: knowledgeSourceContent,
|
|
6364
6366
|
});
|
|
6365
6367
|
},
|
|
6366
6368
|
/**
|
|
@@ -6388,7 +6390,7 @@
|
|
|
6388
6390
|
* Parses the section command
|
|
6389
6391
|
*
|
|
6390
6392
|
* @see `documentationUrl` for more details
|
|
6391
|
-
* @
|
|
6393
|
+
* @public exported from `@promptbook/editable`
|
|
6392
6394
|
*/
|
|
6393
6395
|
var sectionCommandParser = {
|
|
6394
6396
|
/**
|
|
@@ -6519,7 +6521,7 @@
|
|
|
6519
6521
|
if (command.taskType === 'KNOWLEDGE') {
|
|
6520
6522
|
knowledgeCommandParser.$applyToPipelineJson({
|
|
6521
6523
|
type: 'KNOWLEDGE',
|
|
6522
|
-
|
|
6524
|
+
knowledgeSourceContent: $taskJson.content, // <- TODO: [🐝][main] !!3 Work with KNOWLEDGE which not referring to the source file or website, but its content itself
|
|
6523
6525
|
}, $pipelineJson);
|
|
6524
6526
|
$taskJson.isTask = false;
|
|
6525
6527
|
return;
|
|
@@ -6664,7 +6666,7 @@
|
|
|
6664
6666
|
* Parses the BOOK_VERSION command
|
|
6665
6667
|
*
|
|
6666
6668
|
* @see `documentationUrl` for more details
|
|
6667
|
-
* @
|
|
6669
|
+
* @public exported from `@promptbook/editable`
|
|
6668
6670
|
*/
|
|
6669
6671
|
var bookVersionCommandParser = {
|
|
6670
6672
|
/**
|
|
@@ -6819,7 +6821,7 @@
|
|
|
6819
6821
|
* Parses the expect command
|
|
6820
6822
|
*
|
|
6821
6823
|
* @see `documentationUrl` for more details
|
|
6822
|
-
* @
|
|
6824
|
+
* @public exported from `@promptbook/editable`
|
|
6823
6825
|
*/
|
|
6824
6826
|
var expectCommandParser = {
|
|
6825
6827
|
/**
|
|
@@ -7151,7 +7153,7 @@
|
|
|
7151
7153
|
* Note: @@@ This command is used as foreach for new commands - it should NOT be used in any `.book.md` file
|
|
7152
7154
|
*
|
|
7153
7155
|
* @see `documentationUrl` for more details
|
|
7154
|
-
* @
|
|
7156
|
+
* @public exported from `@promptbook/editable`
|
|
7155
7157
|
*/
|
|
7156
7158
|
var foreachCommandParser = {
|
|
7157
7159
|
/**
|
|
@@ -7305,7 +7307,7 @@
|
|
|
7305
7307
|
* Parses the format command
|
|
7306
7308
|
*
|
|
7307
7309
|
* @see `documentationUrl` for more details
|
|
7308
|
-
* @
|
|
7310
|
+
* @public exported from `@promptbook/editable`
|
|
7309
7311
|
*/
|
|
7310
7312
|
var formatCommandParser = {
|
|
7311
7313
|
/**
|
|
@@ -7602,7 +7604,7 @@
|
|
|
7602
7604
|
* Note: @@@ This command is used as formfactor for new commands - it should NOT be used in any `.book.md` file
|
|
7603
7605
|
*
|
|
7604
7606
|
* @see `documentationUrl` for more details
|
|
7605
|
-
* @
|
|
7607
|
+
* @public exported from `@promptbook/editable`
|
|
7606
7608
|
*/
|
|
7607
7609
|
var formfactorCommandParser = {
|
|
7608
7610
|
/**
|
|
@@ -7691,7 +7693,7 @@
|
|
|
7691
7693
|
* Parses the joker command
|
|
7692
7694
|
*
|
|
7693
7695
|
* @see `documentationUrl` for more details
|
|
7694
|
-
* @
|
|
7696
|
+
* @public exported from `@promptbook/editable`
|
|
7695
7697
|
*/
|
|
7696
7698
|
var jokerCommandParser = {
|
|
7697
7699
|
/**
|
|
@@ -7768,7 +7770,8 @@
|
|
|
7768
7770
|
* Parses the model command
|
|
7769
7771
|
*
|
|
7770
7772
|
* @see `documentationUrl` for more details
|
|
7771
|
-
* @
|
|
7773
|
+
* @deprecated Option to manually set the model requirements is not recommended to use, use `PERSONA` instead
|
|
7774
|
+
* @public exported from `@promptbook/editable`
|
|
7772
7775
|
*/
|
|
7773
7776
|
var modelCommandParser = {
|
|
7774
7777
|
/**
|
|
@@ -7912,7 +7915,7 @@
|
|
|
7912
7915
|
* Parses the parameter command
|
|
7913
7916
|
*
|
|
7914
7917
|
* @see `documentationUrl` for more details
|
|
7915
|
-
* @
|
|
7918
|
+
* @public exported from `@promptbook/editable`
|
|
7916
7919
|
*/
|
|
7917
7920
|
var parameterCommandParser = {
|
|
7918
7921
|
/**
|
|
@@ -8017,7 +8020,7 @@
|
|
|
8017
8020
|
* Parses the persona command
|
|
8018
8021
|
*
|
|
8019
8022
|
* @see `documentationUrl` for more details
|
|
8020
|
-
* @
|
|
8023
|
+
* @public exported from `@promptbook/editable`
|
|
8021
8024
|
*/
|
|
8022
8025
|
var personaCommandParser = {
|
|
8023
8026
|
/**
|
|
@@ -8152,7 +8155,7 @@
|
|
|
8152
8155
|
* Parses the postprocess command
|
|
8153
8156
|
*
|
|
8154
8157
|
* @see `documentationUrl` for more details
|
|
8155
|
-
* @
|
|
8158
|
+
* @public exported from `@promptbook/editable`
|
|
8156
8159
|
*/
|
|
8157
8160
|
var postprocessCommandParser = {
|
|
8158
8161
|
/**
|
|
@@ -8230,7 +8233,7 @@
|
|
|
8230
8233
|
* Parses the url command
|
|
8231
8234
|
*
|
|
8232
8235
|
* @see `documentationUrl` for more details
|
|
8233
|
-
* @
|
|
8236
|
+
* @public exported from `@promptbook/editable`
|
|
8234
8237
|
*/
|
|
8235
8238
|
var urlCommandParser = {
|
|
8236
8239
|
/**
|
|
@@ -8331,7 +8334,7 @@
|
|
|
8331
8334
|
* Parses the action command
|
|
8332
8335
|
*
|
|
8333
8336
|
* @see `documentationUrl` for more details
|
|
8334
|
-
* @
|
|
8337
|
+
* @public exported from `@promptbook/editable`
|
|
8335
8338
|
*/
|
|
8336
8339
|
var actionCommandParser = {
|
|
8337
8340
|
/**
|
|
@@ -8397,7 +8400,7 @@
|
|
|
8397
8400
|
* Parses the instrument command
|
|
8398
8401
|
*
|
|
8399
8402
|
* @see `documentationUrl` for more details
|
|
8400
|
-
* @
|
|
8403
|
+
* @public exported from `@promptbook/editable`
|
|
8401
8404
|
*/
|
|
8402
8405
|
var instrumentCommandParser = {
|
|
8403
8406
|
/**
|
|
@@ -8462,7 +8465,7 @@
|
|
|
8462
8465
|
/**
|
|
8463
8466
|
* All available command parsers
|
|
8464
8467
|
*
|
|
8465
|
-
* @
|
|
8468
|
+
* @public exported from `@promptbook/editable`
|
|
8466
8469
|
*/
|
|
8467
8470
|
var COMMANDS = [
|
|
8468
8471
|
sectionCommandParser,
|
|
@@ -8493,7 +8496,7 @@
|
|
|
8493
8496
|
* @returns the parser for the command
|
|
8494
8497
|
* @throws {UnexpectedError} if the parser is not found
|
|
8495
8498
|
*
|
|
8496
|
-
* @
|
|
8499
|
+
* @public exported from `@promptbook/editable`
|
|
8497
8500
|
*/
|
|
8498
8501
|
function getParserForCommand(command) {
|
|
8499
8502
|
var commandParser = COMMANDS.find(function (commandParser) { return commandParser.name === command.type; });
|
|
@@ -8529,7 +8532,7 @@
|
|
|
8529
8532
|
* @returns parsed command object
|
|
8530
8533
|
* @throws {ParseError} if the command is invalid
|
|
8531
8534
|
*
|
|
8532
|
-
* @
|
|
8535
|
+
* @public exported from `@promptbook/editable`
|
|
8533
8536
|
*/
|
|
8534
8537
|
function parseCommand(raw, usagePlace) {
|
|
8535
8538
|
if (raw.includes('\n') || raw.includes('\r')) {
|