@promptbook/core 0.40.0-2 → 0.40.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/esm/index.es.js +221 -34
- package/esm/index.es.js.map +1 -1
- package/esm/typings/_packages/core.index.d.ts +5 -1
- package/esm/typings/errors/PromptbookReferenceError.d.ts +7 -0
- package/esm/typings/execution/createPromptbookExecutor.d.ts +1 -1
- package/esm/typings/library/PromptbookLibrary.d.ts +1 -1
- package/esm/typings/library/SimplePromptbookLibrary.d.ts +7 -13
- package/esm/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +7 -0
- package/esm/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +16 -0
- package/esm/typings/library/constructors/createPromptbookSublibrary.d.ts +6 -0
- package/package.json +1 -1
- package/umd/index.umd.js +223 -33
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/_packages/core.index.d.ts +5 -1
- package/umd/typings/errors/PromptbookReferenceError.d.ts +7 -0
- package/umd/typings/execution/createPromptbookExecutor.d.ts +1 -1
- package/umd/typings/library/PromptbookLibrary.d.ts +1 -1
- package/umd/typings/library/SimplePromptbookLibrary.d.ts +7 -13
- package/umd/typings/library/constructors/createPromptbookLibraryFromPromise.d.ts +7 -0
- package/umd/typings/library/constructors/createPromptbookLibraryFromSources.d.ts +16 -0
- package/umd/typings/library/constructors/createPromptbookSublibrary.d.ts +6 -0
package/umd/index.umd.js
CHANGED
|
@@ -427,7 +427,7 @@
|
|
|
427
427
|
/**
|
|
428
428
|
* The version of the Promptbook library
|
|
429
429
|
*/
|
|
430
|
-
var PROMPTBOOK_VERSION = '0.40.0-
|
|
430
|
+
var PROMPTBOOK_VERSION = '0.40.0-3';
|
|
431
431
|
|
|
432
432
|
/**
|
|
433
433
|
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
@@ -2085,62 +2085,64 @@
|
|
|
2085
2085
|
return NotFoundError;
|
|
2086
2086
|
}(Error));
|
|
2087
2087
|
|
|
2088
|
+
/**
|
|
2089
|
+
* This error indicates errors in referencing promptbooks between each other
|
|
2090
|
+
*/
|
|
2091
|
+
var PromptbookReferenceError = /** @class */ (function (_super) {
|
|
2092
|
+
__extends(PromptbookReferenceError, _super);
|
|
2093
|
+
function PromptbookReferenceError(message) {
|
|
2094
|
+
var _this = _super.call(this, message) || this;
|
|
2095
|
+
_this.name = 'PromptbookReferenceError';
|
|
2096
|
+
Object.setPrototypeOf(_this, PromptbookReferenceError.prototype);
|
|
2097
|
+
return _this;
|
|
2098
|
+
}
|
|
2099
|
+
return PromptbookReferenceError;
|
|
2100
|
+
}(Error));
|
|
2101
|
+
|
|
2088
2102
|
/**
|
|
2089
2103
|
* Library of promptbooks that groups together promptbooks for an application.
|
|
2090
|
-
* This implementation is a very thin wrapper around the Array /
|
|
2104
|
+
* This implementation is a very thin wrapper around the Array / Map of promptbooks.
|
|
2091
2105
|
*
|
|
2092
2106
|
* @see https://github.com/webgptorg/promptbook#promptbook-library
|
|
2093
2107
|
*/
|
|
2094
2108
|
var SimplePromptbookLibrary = /** @class */ (function () {
|
|
2095
|
-
|
|
2096
|
-
this.options = options;
|
|
2097
|
-
}
|
|
2098
|
-
/**
|
|
2099
|
-
* Constructs Promptbook from any sources
|
|
2109
|
+
/**!!!
|
|
2100
2110
|
*
|
|
2101
|
-
*
|
|
2102
|
-
* Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
|
|
2111
|
+
* @param promptbooks !!!
|
|
2103
2112
|
*
|
|
2104
|
-
*
|
|
2105
|
-
*
|
|
2106
|
-
* @returns PromptbookLibrary
|
|
2113
|
+
* Note: During the construction logic of all promptbooks are validated
|
|
2114
|
+
* Note: It is not recommended to use this constructor directly, use `createPromptbookLibraryFromSources` *(or other variant)* instead
|
|
2107
2115
|
*/
|
|
2108
|
-
|
|
2116
|
+
function SimplePromptbookLibrary() {
|
|
2109
2117
|
var e_1, _a;
|
|
2110
|
-
var
|
|
2118
|
+
var promptbooks = [];
|
|
2119
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2120
|
+
promptbooks[_i] = arguments[_i];
|
|
2121
|
+
}
|
|
2122
|
+
this.library = new Map();
|
|
2111
2123
|
try {
|
|
2112
|
-
for (var
|
|
2113
|
-
var
|
|
2114
|
-
var promptbook = void 0;
|
|
2115
|
-
if (typeof source === 'string') {
|
|
2116
|
-
// Note: When directly creating from string, no need to validate the source
|
|
2117
|
-
// The validation is performed always before execution
|
|
2118
|
-
promptbook = promptbookStringToJson(source);
|
|
2119
|
-
}
|
|
2120
|
-
else {
|
|
2121
|
-
promptbook = source;
|
|
2122
|
-
}
|
|
2123
|
-
validatePromptbookJson(promptbook);
|
|
2124
|
+
for (var promptbooks_1 = __values(promptbooks), promptbooks_1_1 = promptbooks_1.next(); !promptbooks_1_1.done; promptbooks_1_1 = promptbooks_1.next()) {
|
|
2125
|
+
var promptbook = promptbooks_1_1.value;
|
|
2124
2126
|
if (promptbook.promptbookUrl === undefined) {
|
|
2125
|
-
throw new
|
|
2127
|
+
throw new PromptbookReferenceError(spaceTrim__default["default"]("\n Promptbook with name \"".concat(promptbook.title, "\" does not have defined URL\n\n Note: Promptbooks without URLs are called anonymous promptbooks\n They can be used as standalone promptbooks, but they cannot be referenced by other promptbooks\n And also they cannot be used in the promptbook library\n\n ")));
|
|
2126
2128
|
}
|
|
2127
|
-
|
|
2129
|
+
validatePromptbookJson(promptbook);
|
|
2130
|
+
this.library.set(promptbook.promptbookUrl, promptbook);
|
|
2128
2131
|
}
|
|
2129
2132
|
}
|
|
2130
2133
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2131
2134
|
finally {
|
|
2132
2135
|
try {
|
|
2133
|
-
if (
|
|
2136
|
+
if (promptbooks_1_1 && !promptbooks_1_1.done && (_a = promptbooks_1.return)) _a.call(promptbooks_1);
|
|
2134
2137
|
}
|
|
2135
2138
|
finally { if (e_1) throw e_1.error; }
|
|
2136
2139
|
}
|
|
2137
|
-
|
|
2138
|
-
};
|
|
2140
|
+
}
|
|
2139
2141
|
/**
|
|
2140
2142
|
* Gets all promptbooks in the library
|
|
2141
2143
|
*/
|
|
2142
2144
|
SimplePromptbookLibrary.prototype.listPromptbooks = function () {
|
|
2143
|
-
return
|
|
2145
|
+
return Array.from(this.library.keys());
|
|
2144
2146
|
};
|
|
2145
2147
|
/**
|
|
2146
2148
|
* Gets promptbook by its URL
|
|
@@ -2149,7 +2151,7 @@
|
|
|
2149
2151
|
*/
|
|
2150
2152
|
SimplePromptbookLibrary.prototype.getPromptbookByUrl = function (url) {
|
|
2151
2153
|
var _this = this;
|
|
2152
|
-
var promptbook = this.
|
|
2154
|
+
var promptbook = this.library.get(url);
|
|
2153
2155
|
if (!promptbook) {
|
|
2154
2156
|
throw new NotFoundError(spaceTrim__default["default"](function (block) { return "\n Promptbook with url \"".concat(url, "\" not found\n\n Available promptbooks:\n ").concat(block(_this.listPromptbooks()
|
|
2155
2157
|
.map(function (promptbookUrl) { return "- ".concat(promptbookUrl); })
|
|
@@ -2166,6 +2168,191 @@
|
|
|
2166
2168
|
return SimplePromptbookLibrary;
|
|
2167
2169
|
}());
|
|
2168
2170
|
|
|
2171
|
+
function createPromptbookLibraryFromSources() {
|
|
2172
|
+
var e_1, _a;
|
|
2173
|
+
var promptbookSources = [];
|
|
2174
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2175
|
+
promptbookSources[_i] = arguments[_i];
|
|
2176
|
+
}
|
|
2177
|
+
var promptbooks = new Array();
|
|
2178
|
+
try {
|
|
2179
|
+
for (var promptbookSources_1 = __values(promptbookSources), promptbookSources_1_1 = promptbookSources_1.next(); !promptbookSources_1_1.done; promptbookSources_1_1 = promptbookSources_1.next()) {
|
|
2180
|
+
var source = promptbookSources_1_1.value;
|
|
2181
|
+
var promptbook = void 0;
|
|
2182
|
+
if (typeof source === 'string') {
|
|
2183
|
+
// Note: When directly creating from string, no need to validate the source
|
|
2184
|
+
// The validation is performed always before execution
|
|
2185
|
+
promptbook = promptbookStringToJson(source);
|
|
2186
|
+
}
|
|
2187
|
+
else {
|
|
2188
|
+
promptbook = source;
|
|
2189
|
+
}
|
|
2190
|
+
promptbooks.push(promptbook);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2194
|
+
finally {
|
|
2195
|
+
try {
|
|
2196
|
+
if (promptbookSources_1_1 && !promptbookSources_1_1.done && (_a = promptbookSources_1.return)) _a.call(promptbookSources_1);
|
|
2197
|
+
}
|
|
2198
|
+
finally { if (e_1) throw e_1.error; }
|
|
2199
|
+
}
|
|
2200
|
+
return new (SimplePromptbookLibrary.bind.apply(SimplePromptbookLibrary, __spreadArray([void 0], __read(promptbooks), false)))();
|
|
2201
|
+
}
|
|
2202
|
+
/**
|
|
2203
|
+
* Constructs Promptbook from any sources
|
|
2204
|
+
*
|
|
2205
|
+
* Note: During the construction syntax and logic of all sources are validated
|
|
2206
|
+
* Note: You can combine .ptbk.md and .ptbk.json files BUT it is not recommended
|
|
2207
|
+
*
|
|
2208
|
+
* @param promptbookSources contents of .ptbk.md or .ptbk.json files
|
|
2209
|
+
* @param settings settings for creating executor functions
|
|
2210
|
+
* @returns PromptbookLibrary
|
|
2211
|
+
*/
|
|
2212
|
+
/***
|
|
2213
|
+
* TODO: !!! Annotate all + all to README and samples
|
|
2214
|
+
*/
|
|
2215
|
+
|
|
2216
|
+
function createPromptbookLibraryFromPromise(promptbookSourcesPromiseOrFactory) {
|
|
2217
|
+
var library;
|
|
2218
|
+
function forSources() {
|
|
2219
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2220
|
+
var promptbookSources;
|
|
2221
|
+
return __generator(this, function (_a) {
|
|
2222
|
+
switch (_a.label) {
|
|
2223
|
+
case 0:
|
|
2224
|
+
if (typeof promptbookSourcesPromiseOrFactory === 'function') {
|
|
2225
|
+
// Note: Calling factory function only once despite multiple calls to resolveSources
|
|
2226
|
+
promptbookSourcesPromiseOrFactory = promptbookSourcesPromiseOrFactory();
|
|
2227
|
+
}
|
|
2228
|
+
return [4 /*yield*/, promptbookSourcesPromiseOrFactory];
|
|
2229
|
+
case 1:
|
|
2230
|
+
promptbookSources = _a.sent();
|
|
2231
|
+
library = createPromptbookLibraryFromSources.apply(void 0, __spreadArray([], __read(promptbookSources), false));
|
|
2232
|
+
return [2 /*return*/];
|
|
2233
|
+
}
|
|
2234
|
+
});
|
|
2235
|
+
});
|
|
2236
|
+
}
|
|
2237
|
+
function listPromptbooks() {
|
|
2238
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2239
|
+
return __generator(this, function (_a) {
|
|
2240
|
+
switch (_a.label) {
|
|
2241
|
+
case 0: return [4 /*yield*/, forSources()];
|
|
2242
|
+
case 1:
|
|
2243
|
+
_a.sent();
|
|
2244
|
+
return [2 /*return*/, /* not await */ library.listPromptbooks()];
|
|
2245
|
+
}
|
|
2246
|
+
});
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
function getPromptbookByUrl(url) {
|
|
2250
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2251
|
+
return __generator(this, function (_a) {
|
|
2252
|
+
switch (_a.label) {
|
|
2253
|
+
case 0: return [4 /*yield*/, forSources()];
|
|
2254
|
+
case 1:
|
|
2255
|
+
_a.sent();
|
|
2256
|
+
return [2 /*return*/, /* not await */ library.getPromptbookByUrl(url)];
|
|
2257
|
+
}
|
|
2258
|
+
});
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
function isResponsibleForPrompt(prompt) {
|
|
2262
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2263
|
+
return __generator(this, function (_a) {
|
|
2264
|
+
switch (_a.label) {
|
|
2265
|
+
case 0: return [4 /*yield*/, forSources()];
|
|
2266
|
+
case 1:
|
|
2267
|
+
_a.sent();
|
|
2268
|
+
return [2 /*return*/, /* not await */ library.isResponsibleForPrompt(prompt)];
|
|
2269
|
+
}
|
|
2270
|
+
});
|
|
2271
|
+
});
|
|
2272
|
+
}
|
|
2273
|
+
return {
|
|
2274
|
+
listPromptbooks: listPromptbooks,
|
|
2275
|
+
getPromptbookByUrl: getPromptbookByUrl,
|
|
2276
|
+
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
2277
|
+
};
|
|
2278
|
+
}
|
|
2279
|
+
/***
|
|
2280
|
+
* TODO: !!! Annotate all + all to README and samples
|
|
2281
|
+
*/
|
|
2282
|
+
|
|
2283
|
+
function createPromptbookSublibrary(library, predicate) {
|
|
2284
|
+
function listPromptbooks() {
|
|
2285
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2286
|
+
var promptbooks;
|
|
2287
|
+
return __generator(this, function (_a) {
|
|
2288
|
+
switch (_a.label) {
|
|
2289
|
+
case 0: return [4 /*yield*/, library.listPromptbooks()];
|
|
2290
|
+
case 1:
|
|
2291
|
+
promptbooks = _a.sent();
|
|
2292
|
+
promptbooks = promptbooks.filter(predicate);
|
|
2293
|
+
return [2 /*return*/, promptbooks];
|
|
2294
|
+
}
|
|
2295
|
+
});
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
function getPromptbookByUrl(url) {
|
|
2299
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2300
|
+
var _a, promptbook;
|
|
2301
|
+
var _this = this;
|
|
2302
|
+
return __generator(this, function (_b) {
|
|
2303
|
+
switch (_b.label) {
|
|
2304
|
+
case 0:
|
|
2305
|
+
if (!!predicate(url)) return [3 /*break*/, 2];
|
|
2306
|
+
_a = NotFoundError.bind;
|
|
2307
|
+
return [4 /*yield*/, spaceTrim__default["default"](function (block) { return __awaiter(_this, void 0, void 0, function () {
|
|
2308
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2309
|
+
return __generator(this, function (_g) {
|
|
2310
|
+
switch (_g.label) {
|
|
2311
|
+
case 0:
|
|
2312
|
+
_c = (_b = "\n Promptbook with url \"".concat(url, "\" not found or not accessible\n\n Available promptbooks:\n ")).concat;
|
|
2313
|
+
_d = block;
|
|
2314
|
+
return [4 /*yield*/, listPromptbooks()];
|
|
2315
|
+
case 1:
|
|
2316
|
+
_e = (_a = _c.apply(_b, [_d.apply(void 0, [(_g.sent()).map(function (promptbookUrl) { return "- ".concat(promptbookUrl); }).join('\n')]), "\n\n All available promptbooks in parent library:\n "])).concat;
|
|
2317
|
+
_f = block;
|
|
2318
|
+
return [4 /*yield*/, library.listPromptbooks()];
|
|
2319
|
+
case 2: return [2 /*return*/, _e.apply(_a, [_f.apply(void 0, [(_g.sent()).map(function (promptbookUrl) { return "- ".concat(promptbookUrl); }).join('\n')]), "\n\n "])];
|
|
2320
|
+
}
|
|
2321
|
+
});
|
|
2322
|
+
}); })];
|
|
2323
|
+
case 1: throw new (_a.apply(NotFoundError, [void 0, _b.sent()]))();
|
|
2324
|
+
case 2: return [4 /*yield*/, library.getPromptbookByUrl(url)];
|
|
2325
|
+
case 3:
|
|
2326
|
+
promptbook = _b.sent();
|
|
2327
|
+
return [2 /*return*/, promptbook];
|
|
2328
|
+
}
|
|
2329
|
+
});
|
|
2330
|
+
});
|
|
2331
|
+
}
|
|
2332
|
+
function isResponsibleForPrompt(prompt) {
|
|
2333
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2334
|
+
var isResponsible;
|
|
2335
|
+
return __generator(this, function (_a) {
|
|
2336
|
+
switch (_a.label) {
|
|
2337
|
+
case 0: return [4 /*yield*/, library.isResponsibleForPrompt(prompt)];
|
|
2338
|
+
case 1:
|
|
2339
|
+
isResponsible = _a.sent();
|
|
2340
|
+
// TODO: !! Only if responsible, check if predicate is true
|
|
2341
|
+
return [2 /*return*/, isResponsible];
|
|
2342
|
+
}
|
|
2343
|
+
});
|
|
2344
|
+
});
|
|
2345
|
+
}
|
|
2346
|
+
return {
|
|
2347
|
+
listPromptbooks: listPromptbooks,
|
|
2348
|
+
getPromptbookByUrl: getPromptbookByUrl,
|
|
2349
|
+
isResponsibleForPrompt: isResponsibleForPrompt,
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
/***
|
|
2353
|
+
* TODO: !!! Annotate all + all to README and samples
|
|
2354
|
+
*/
|
|
2355
|
+
|
|
2169
2356
|
exports.CallbackInterfaceTools = CallbackInterfaceTools;
|
|
2170
2357
|
exports.ExecutionTypes = ExecutionTypes;
|
|
2171
2358
|
exports.MockedEchoNaturalExecutionTools = MockedEchoNaturalExecutionTools;
|
|
@@ -2173,6 +2360,9 @@
|
|
|
2173
2360
|
exports.SimplePromptInterfaceTools = SimplePromptInterfaceTools;
|
|
2174
2361
|
exports.SimplePromptbookLibrary = SimplePromptbookLibrary;
|
|
2175
2362
|
exports.createPromptbookExecutor = createPromptbookExecutor;
|
|
2363
|
+
exports.createPromptbookLibraryFromPromise = createPromptbookLibraryFromPromise;
|
|
2364
|
+
exports.createPromptbookLibraryFromSources = createPromptbookLibraryFromSources;
|
|
2365
|
+
exports.createPromptbookSublibrary = createPromptbookSublibrary;
|
|
2176
2366
|
exports.promptbookStringToJson = promptbookStringToJson;
|
|
2177
2367
|
exports.validatePromptbookJson = validatePromptbookJson;
|
|
2178
2368
|
|