@promptbook/core 0.84.0-10 → 0.84.0-11
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 +148 -96
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +3 -1
- package/esm/typings/src/pipeline/book-notation.d.ts +3 -2
- package/esm/typings/src/pipeline/prompt-notation.d.ts +18 -5
- package/package.json +1 -1
- package/umd/index.umd.js +148 -96
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -25,7 +25,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-
|
|
28
|
+
var PROMPTBOOK_ENGINE_VERSION = '0.84.0-10';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -178,22 +178,94 @@ function collectionToJson(collection) {
|
|
|
178
178
|
*/
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
|
-
*
|
|
181
|
+
* Checks if value is valid email
|
|
182
182
|
*
|
|
183
183
|
* @public exported from `@promptbook/utils`
|
|
184
184
|
*/
|
|
185
|
-
function
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
function isValidEmail(email) {
|
|
186
|
+
if (typeof email !== 'string') {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
if (email.split('\n').length > 1) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
return /^.+@.+\..+$/.test(email);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Tests if given string is valid URL.
|
|
197
|
+
*
|
|
198
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
199
|
+
* @public exported from `@promptbook/utils`
|
|
200
|
+
*/
|
|
201
|
+
function isValidFilePath(filename) {
|
|
202
|
+
if (typeof filename !== 'string') {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
if (filename.split('\n').length > 1) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
if (filename.split(' ').length >
|
|
209
|
+
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
var filenameSlashes = filename.split('\\').join('/');
|
|
213
|
+
// Absolute Unix path: /hello.txt
|
|
214
|
+
if (/^(\/)/i.test(filenameSlashes)) {
|
|
215
|
+
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
188
216
|
return true;
|
|
189
217
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
218
|
+
// Absolute Windows path: /hello.txt
|
|
219
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
220
|
+
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
// Relative path: ./hello.txt
|
|
224
|
+
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
225
|
+
// console.log(filename, 'Relative path: ./hello.txt');
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
// Allow paths like foo/hello
|
|
229
|
+
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
230
|
+
// console.log(filename, 'Allow paths like foo/hello');
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
// Allow paths like hello.book
|
|
234
|
+
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
235
|
+
// console.log(filename, 'Allow paths like hello.book');
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* TODO: [🍏] Implement for MacOs
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Tests if given string is valid URL.
|
|
246
|
+
*
|
|
247
|
+
* Note: Dataurl are considered perfectly valid.
|
|
248
|
+
* Note: There are two simmilar functions:
|
|
249
|
+
* - `isValidUrl` which tests any URL
|
|
250
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
251
|
+
*
|
|
252
|
+
* @public exported from `@promptbook/utils`
|
|
253
|
+
*/
|
|
254
|
+
function isValidUrl(url) {
|
|
255
|
+
if (typeof url !== 'string') {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
if (url.startsWith('blob:')) {
|
|
260
|
+
url = url.replace(/^blob:/, '');
|
|
193
261
|
}
|
|
194
|
-
|
|
262
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
263
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
195
264
|
return false;
|
|
196
265
|
}
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
197
269
|
return false;
|
|
198
270
|
}
|
|
199
271
|
}
|
|
@@ -217,6 +289,27 @@ var ParseError = /** @class */ (function (_super) {
|
|
|
217
289
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
218
290
|
*/
|
|
219
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
294
|
+
*
|
|
295
|
+
* @public exported from `@promptbook/utils`
|
|
296
|
+
*/
|
|
297
|
+
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
298
|
+
try {
|
|
299
|
+
JSON.parse(value);
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
if (!(error instanceof Error)) {
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
if (error.message.includes('Unexpected token')) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
220
313
|
/**
|
|
221
314
|
* Function `validatePipelineString` will validate the if the string is a valid pipeline string
|
|
222
315
|
* It does not check if the string is fully logically correct, but if it is a string that can be a pipeline string or the string looks completely different.
|
|
@@ -230,6 +323,15 @@ function validatePipelineString(pipelineString) {
|
|
|
230
323
|
if (isValidJsonString(pipelineString)) {
|
|
231
324
|
throw new ParseError('Expected a book, but got a JSON string');
|
|
232
325
|
}
|
|
326
|
+
else if (isValidUrl(pipelineString)) {
|
|
327
|
+
throw new ParseError("Expected a book, but got just the URL \"".concat(pipelineString, "\""));
|
|
328
|
+
}
|
|
329
|
+
else if (isValidFilePath(pipelineString)) {
|
|
330
|
+
throw new ParseError("Expected a book, but got just the file path \"".concat(pipelineString, "\""));
|
|
331
|
+
}
|
|
332
|
+
else if (isValidEmail(pipelineString)) {
|
|
333
|
+
throw new ParseError("Expected a book, but got just the email \"".concat(pipelineString, "\""));
|
|
334
|
+
}
|
|
233
335
|
// <- TODO: Implement the validation + add tests when the pipeline logic considered as invalid
|
|
234
336
|
return pipelineString;
|
|
235
337
|
}
|
|
@@ -1183,35 +1285,6 @@ function isUrlOnPrivateNetwork(url) {
|
|
|
1183
1285
|
return isHostnameOnPrivateNetwork(url.hostname);
|
|
1184
1286
|
}
|
|
1185
1287
|
|
|
1186
|
-
/**
|
|
1187
|
-
* Tests if given string is valid URL.
|
|
1188
|
-
*
|
|
1189
|
-
* Note: Dataurl are considered perfectly valid.
|
|
1190
|
-
* Note: There are two simmilar functions:
|
|
1191
|
-
* - `isValidUrl` which tests any URL
|
|
1192
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1193
|
-
*
|
|
1194
|
-
* @public exported from `@promptbook/utils`
|
|
1195
|
-
*/
|
|
1196
|
-
function isValidUrl(url) {
|
|
1197
|
-
if (typeof url !== 'string') {
|
|
1198
|
-
return false;
|
|
1199
|
-
}
|
|
1200
|
-
try {
|
|
1201
|
-
if (url.startsWith('blob:')) {
|
|
1202
|
-
url = url.replace(/^blob:/, '');
|
|
1203
|
-
}
|
|
1204
|
-
var urlObject = new URL(url /* because fail is handled */);
|
|
1205
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1206
|
-
return false;
|
|
1207
|
-
}
|
|
1208
|
-
return true;
|
|
1209
|
-
}
|
|
1210
|
-
catch (error) {
|
|
1211
|
-
return false;
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
1288
|
/**
|
|
1216
1289
|
* Tests if given string is valid pipeline URL URL.
|
|
1217
1290
|
*
|
|
@@ -2170,12 +2243,28 @@ function deserializeError(error) {
|
|
|
2170
2243
|
/**
|
|
2171
2244
|
* Asserts that the execution of a Promptbook is successful
|
|
2172
2245
|
*
|
|
2246
|
+
* Note: If there are only warnings, the execution is still successful but the warnings are logged in the console
|
|
2247
|
+
*
|
|
2173
2248
|
* @param executionResult - The partial result of the Promptbook execution
|
|
2174
2249
|
* @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
|
|
2175
2250
|
* @public exported from `@promptbook/core`
|
|
2176
2251
|
*/
|
|
2177
2252
|
function assertsExecutionSuccessful(executionResult) {
|
|
2178
|
-
var
|
|
2253
|
+
var e_1, _a;
|
|
2254
|
+
var isSuccessful = executionResult.isSuccessful, errors = executionResult.errors, warnings = executionResult.warnings;
|
|
2255
|
+
try {
|
|
2256
|
+
for (var warnings_1 = __values(warnings), warnings_1_1 = warnings_1.next(); !warnings_1_1.done; warnings_1_1 = warnings_1.next()) {
|
|
2257
|
+
var warning = warnings_1_1.value;
|
|
2258
|
+
console.warn(warning.message);
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2262
|
+
finally {
|
|
2263
|
+
try {
|
|
2264
|
+
if (warnings_1_1 && !warnings_1_1.done && (_a = warnings_1.return)) _a.call(warnings_1);
|
|
2265
|
+
}
|
|
2266
|
+
finally { if (e_1) throw e_1.error; }
|
|
2267
|
+
}
|
|
2179
2268
|
if (isSuccessful === true) {
|
|
2180
2269
|
return;
|
|
2181
2270
|
}
|
|
@@ -5715,55 +5804,6 @@ function isFileExisting(filename, fs) {
|
|
|
5715
5804
|
* TODO: [🖇] What about symlinks?
|
|
5716
5805
|
*/
|
|
5717
5806
|
|
|
5718
|
-
/**
|
|
5719
|
-
* Tests if given string is valid URL.
|
|
5720
|
-
*
|
|
5721
|
-
* Note: This does not check if the file exists only if the path is valid
|
|
5722
|
-
* @public exported from `@promptbook/utils`
|
|
5723
|
-
*/
|
|
5724
|
-
function isValidFilePath(filename) {
|
|
5725
|
-
if (typeof filename !== 'string') {
|
|
5726
|
-
return false;
|
|
5727
|
-
}
|
|
5728
|
-
if (filename.split('\n').length > 1) {
|
|
5729
|
-
return false;
|
|
5730
|
-
}
|
|
5731
|
-
if (filename.split(' ').length >
|
|
5732
|
-
5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
|
|
5733
|
-
return false;
|
|
5734
|
-
}
|
|
5735
|
-
var filenameSlashes = filename.split('\\').join('/');
|
|
5736
|
-
// Absolute Unix path: /hello.txt
|
|
5737
|
-
if (/^(\/)/i.test(filenameSlashes)) {
|
|
5738
|
-
// console.log(filename, 'Absolute Unix path: /hello.txt');
|
|
5739
|
-
return true;
|
|
5740
|
-
}
|
|
5741
|
-
// Absolute Windows path: /hello.txt
|
|
5742
|
-
if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
|
|
5743
|
-
// console.log(filename, 'Absolute Windows path: /hello.txt');
|
|
5744
|
-
return true;
|
|
5745
|
-
}
|
|
5746
|
-
// Relative path: ./hello.txt
|
|
5747
|
-
if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
|
|
5748
|
-
// console.log(filename, 'Relative path: ./hello.txt');
|
|
5749
|
-
return true;
|
|
5750
|
-
}
|
|
5751
|
-
// Allow paths like foo/hello
|
|
5752
|
-
if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
|
|
5753
|
-
// console.log(filename, 'Allow paths like foo/hello');
|
|
5754
|
-
return true;
|
|
5755
|
-
}
|
|
5756
|
-
// Allow paths like hello.book
|
|
5757
|
-
if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
|
|
5758
|
-
// console.log(filename, 'Allow paths like hello.book');
|
|
5759
|
-
return true;
|
|
5760
|
-
}
|
|
5761
|
-
return false;
|
|
5762
|
-
}
|
|
5763
|
-
/**
|
|
5764
|
-
* TODO: [🍏] Implement for MacOs
|
|
5765
|
-
*/
|
|
5766
|
-
|
|
5767
5807
|
/**
|
|
5768
5808
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5769
5809
|
*
|
|
@@ -11075,13 +11115,14 @@ function isValidPipelineString(pipelineString) {
|
|
|
11075
11115
|
/**
|
|
11076
11116
|
* Tag function for notating a prompt as template literal
|
|
11077
11117
|
*
|
|
11078
|
-
* Note: There are
|
|
11118
|
+
* Note: There are 3 similar functions:
|
|
11079
11119
|
* 1) `prompt` for notating single prompt exported from `@promptbook/utils`
|
|
11080
|
-
*
|
|
11120
|
+
* 2) `promptTemplate` alias for `prompt`
|
|
11121
|
+
* 3) `book` for notating and validating entire books exported from `@promptbook/utils`
|
|
11081
11122
|
*
|
|
11082
|
-
* @param strings
|
|
11083
|
-
* @param values
|
|
11084
|
-
* @returns the
|
|
11123
|
+
* @param strings
|
|
11124
|
+
* @param values
|
|
11125
|
+
* @returns the prompt string
|
|
11085
11126
|
* @public exported from `@promptbook/utils`
|
|
11086
11127
|
*/
|
|
11087
11128
|
function prompt(strings) {
|
|
@@ -11092,10 +11133,14 @@ function prompt(strings) {
|
|
|
11092
11133
|
if (values.length === 0) {
|
|
11093
11134
|
return spaceTrim(strings.join(''));
|
|
11094
11135
|
}
|
|
11136
|
+
var stringsWithHiddenParameters = strings.map(function (stringsItem) {
|
|
11137
|
+
// TODO: [0] DRY
|
|
11138
|
+
return stringsItem.split('{').join("".concat(REPLACING_NONCE, "beginbracket")).split('}').join("".concat(REPLACING_NONCE, "endbracket"));
|
|
11139
|
+
});
|
|
11095
11140
|
var placeholderParameterNames = values.map(function (value, i) { return "".concat(REPLACING_NONCE).concat(i); });
|
|
11096
11141
|
var parameters = Object.fromEntries(values.map(function (value, i) { return [placeholderParameterNames[i], value]; }));
|
|
11097
11142
|
// Combine strings and values
|
|
11098
|
-
var pipelineString =
|
|
11143
|
+
var pipelineString = stringsWithHiddenParameters.reduce(function (result, stringsItem, i) {
|
|
11099
11144
|
return placeholderParameterNames[i] === undefined
|
|
11100
11145
|
? "".concat(result).concat(stringsItem)
|
|
11101
11146
|
: "".concat(result).concat(stringsItem, "{").concat(placeholderParameterNames[i], "}");
|
|
@@ -11111,6 +11156,12 @@ function prompt(strings) {
|
|
|
11111
11156
|
console.error({ pipelineString: pipelineString, parameters: parameters, placeholderParameterNames: placeholderParameterNames, error: error });
|
|
11112
11157
|
throw new UnexpectedError(spaceTrim(function (block) { return "\n Internal error in prompt template literal\n \n ".concat(block(JSON.stringify({ strings: strings, values: values }, null, 4)), "}\n \n "); }));
|
|
11113
11158
|
}
|
|
11159
|
+
// TODO: [0] DRY
|
|
11160
|
+
pipelineString = pipelineString
|
|
11161
|
+
.split("".concat(REPLACING_NONCE, "beginbracket"))
|
|
11162
|
+
.join('{')
|
|
11163
|
+
.split("".concat(REPLACING_NONCE, "endbracket"))
|
|
11164
|
+
.join('}');
|
|
11114
11165
|
return pipelineString;
|
|
11115
11166
|
}
|
|
11116
11167
|
/**
|
|
@@ -11121,9 +11172,10 @@ function prompt(strings) {
|
|
|
11121
11172
|
/**
|
|
11122
11173
|
* Tag function for notating a pipeline with a book\`...\ notation as template literal
|
|
11123
11174
|
*
|
|
11124
|
-
* Note: There are
|
|
11175
|
+
* Note: There are 3 similar functions:
|
|
11125
11176
|
* 1) `prompt` for notating single prompt exported from `@promptbook/utils`
|
|
11126
|
-
*
|
|
11177
|
+
* 2) `promptTemplate` alias for `prompt`
|
|
11178
|
+
* 3) `book` for notating and validating entire books exported from `@promptbook/utils`
|
|
11127
11179
|
*
|
|
11128
11180
|
* @param strings @@@
|
|
11129
11181
|
* @param values @@@
|