@promptbook/legacy-documents 0.81.0-11 → 0.81.0-13

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 CHANGED
@@ -257,7 +257,7 @@ Or you can install them separately:
257
257
  - **[@promptbook/editable](https://www.npmjs.com/package/@promptbook/editable)** - Editable book as native javascript object with imperative object API
258
258
  - **[@promptbook/templates](https://www.npmjs.com/package/@promptbook/templates)** - Usefull templates and examples of books which can be used as a starting point
259
259
  - **[@promptbook/types](https://www.npmjs.com/package/@promptbook/types)** - Just typescript types used in the library
260
- - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
260
+ - **[@promptbook/cli](https://www.npmjs.com/package/@promptbook/cli)** - Command line interface utilities for promptbooks
261
261
 
262
262
 
263
263
 
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.81.0-10';
28
+ var PROMPTBOOK_ENGINE_VERSION = '0.81.0-12';
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
@@ -945,21 +945,44 @@ function isValidFilePath(filename) {
945
945
  if (typeof filename !== 'string') {
946
946
  return false;
947
947
  }
948
+ if (filename.split('\n').length > 1) {
949
+ return false;
950
+ }
951
+ if (filename.split(' ').length >
952
+ 5 /* <- TODO: [🧠][🈷] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
953
+ return false;
954
+ }
948
955
  var filenameSlashes = filename.split('\\').join('/');
949
956
  // Absolute Unix path: /hello.txt
950
957
  if (/^(\/)/i.test(filenameSlashes)) {
958
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
951
959
  return true;
952
960
  }
953
961
  // Absolute Windows path: /hello.txt
954
962
  if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
963
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
955
964
  return true;
956
965
  }
957
966
  // Relative path: ./hello.txt
958
967
  if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
968
+ // console.log(filename, 'Relative path: ./hello.txt');
969
+ return true;
970
+ }
971
+ // Allow paths like foo/hello
972
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
973
+ // console.log(filename, 'Allow paths like foo/hello');
974
+ return true;
975
+ }
976
+ // Allow paths like hello.book
977
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
978
+ // console.log(filename, 'Allow paths like hello.book');
959
979
  return true;
960
980
  }
961
981
  return false;
962
982
  }
983
+ /**
984
+ * TODO: [🍏] Implement for MacOs
985
+ */
963
986
 
964
987
  /**
965
988
  * Tests if given string is valid URL.
@@ -1477,7 +1500,7 @@ function checkSerializableAsJson(options) {
1477
1500
  if (!(error instanceof Error)) {
1478
1501
  throw error;
1479
1502
  }
1480
- throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.toString()), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1503
+ throw new UnexpectedError(spaceTrim$1(function (block) { return "\n `".concat(name, "` is not serializable\n\n ").concat(block(error.stack || error.message), "\n\n Additional message for `").concat(name, "`:\n ").concat(block(message || '(nothing)'), "\n "); }));
1481
1504
  }
1482
1505
  /*
1483
1506
  TODO: [0] Is there some more elegant way to check circular references?
@@ -3618,6 +3641,9 @@ var scraperFetch = function (url, init) { return __awaiter(void 0, void 0, void
3618
3641
  }
3619
3642
  });
3620
3643
  }); };
3644
+ /**
3645
+ * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
3646
+ */
3621
3647
 
3622
3648
  /**
3623
3649
  * @@@
@@ -3685,7 +3711,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3685
3711
  },
3686
3712
  }];
3687
3713
  case 2:
3688
- if (!(isValidFilePath(sourceContent) || /\.[a-z]{1,10}$/i.exec(sourceContent))) return [3 /*break*/, 4];
3714
+ if (!isValidFilePath(sourceContent)) return [3 /*break*/, 4];
3689
3715
  if (tools.fs === undefined) {
3690
3716
  throw new EnvironmentMismatchError('Can not import file knowledge without filesystem tools');
3691
3717
  // <- TODO: [🧠] What is the best error type here`
@@ -3700,7 +3726,7 @@ function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3700
3726
  return [4 /*yield*/, isFileExisting(filename_1, tools.fs)];
3701
3727
  case 3:
3702
3728
  if (!(_f.sent())) {
3703
- throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(filename_1), "\n "); }));
3729
+ throw new NotFoundError(spaceTrim$1(function (block) { return "\n Can not make source handler for file which does not exist:\n\n File:\n ".concat(block(sourceContent), "\n\n Full file path:\n ").concat(block(filename_1), "\n "); }));
3704
3730
  }
3705
3731
  // TODO: [🧠][😿] Test security file - file is scoped to the project (BUT maybe do this in `filesystemTools`)
3706
3732
  return [2 /*return*/, {
@@ -4108,7 +4134,7 @@ function extractVariablesFromScript(script) {
4108
4134
  if (!(error instanceof Error)) {
4109
4135
  throw error;
4110
4136
  }
4111
- throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.toString()), "}\n\n\n Found variables:\n\n ").concat(Array.from(variables)
4137
+ throw new ParseError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n ".concat(block(error.stack || error.message), "\n\n Found variables:\n ").concat(Array.from(variables)
4112
4138
  .map(function (variableName, i) { return "".concat(i + 1, ") ").concat(variableName); })
4113
4139
  .join('\n'), "\n\n\n The script:\n\n ```javascript\n ").concat(block(originalScript), "\n ```\n "); }));
4114
4140
  }