@promptbook/markdown-utils 0.77.0 → 0.77.1

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 CHANGED
@@ -20,7 +20,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
20
20
  *
21
21
  * @see https://github.com/webgptorg/promptbook
22
22
  */
23
- var PROMPTBOOK_ENGINE_VERSION = '0.77.0-6';
23
+ var PROMPTBOOK_ENGINE_VERSION = '0.77.0';
24
24
  /**
25
25
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
26
26
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2123,7 +2123,7 @@ var NotYetImplementedError = /** @class */ (function (_super) {
2123
2123
  *
2124
2124
  * @public exported from `@promptbook/core`
2125
2125
  */
2126
- var ERRORS = {
2126
+ var PROMPTBOOK_ERRORS = {
2127
2127
  AbstractFormatError: AbstractFormatError,
2128
2128
  CsvFormatError: CsvFormatError,
2129
2129
  CollectionError: CollectionError,
@@ -2141,6 +2141,35 @@ var ERRORS = {
2141
2141
  UnexpectedError: UnexpectedError,
2142
2142
  // TODO: [🪑]> VersionMismatchError,
2143
2143
  };
2144
+ /**
2145
+ * Index of all javascript errors
2146
+ *
2147
+ * @private for internal usage
2148
+ */
2149
+ var COMMON_JAVASCRIPT_ERRORS = {
2150
+ Error: Error,
2151
+ EvalError: EvalError,
2152
+ RangeError: RangeError,
2153
+ ReferenceError: ReferenceError,
2154
+ SyntaxError: SyntaxError,
2155
+ TypeError: TypeError,
2156
+ URIError: URIError,
2157
+ AggregateError: AggregateError,
2158
+ /*
2159
+ Note: Not widely supported
2160
+ > InternalError,
2161
+ > ModuleError,
2162
+ > HeapError,
2163
+ > WebAssemblyCompileError,
2164
+ > WebAssemblyRuntimeError,
2165
+ */
2166
+ };
2167
+ /**
2168
+ * Index of all errors
2169
+ *
2170
+ * @private for internal usage
2171
+ */
2172
+ var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
2144
2173
  /**
2145
2174
  * Note: [💞] Ignore a discrepancy between file name and entity name
2146
2175
  */
@@ -2151,11 +2180,11 @@ var ERRORS = {
2151
2180
  * @public exported from `@promptbook/utils`
2152
2181
  */
2153
2182
  function deserializeError(error) {
2154
- if (error.name === 'Error') {
2155
- return new Error(error.message);
2183
+ var ErrorClass = ALL_ERRORS[error.name];
2184
+ if (ErrorClass === undefined) {
2185
+ return new Error("".concat(error.name, ": ").concat(error.message));
2156
2186
  }
2157
- var CustomError = ERRORS[error.name];
2158
- return new CustomError(error.message);
2187
+ return new ErrorClass(error.message);
2159
2188
  }
2160
2189
 
2161
2190
  /**
@@ -2229,8 +2258,8 @@ function isPipelinePrepared(pipeline) {
2229
2258
  */
2230
2259
  function serializeError(error) {
2231
2260
  var name = error.name, message = error.message, stack = error.stack;
2232
- if (!__spreadArray(['Error'], __read(Object.keys(ERRORS)), false).includes(name)) {
2233
- throw new UnexpectedError(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
2261
+ if (!Object.keys(ALL_ERRORS).includes(name)) {
2262
+ console.error(spaceTrim(function (block) { return "\n \n Cannot serialize error with name \"".concat(name, "\"\n\n ").concat(block(stack || message), "\n \n "); }));
2234
2263
  }
2235
2264
  return {
2236
2265
  name: name,
@@ -5838,18 +5867,19 @@ function addAutoGeneratedSection(content, options) {
5838
5867
  var warningLine = "<!-- ".concat(GENERATOR_WARNING, " -->");
5839
5868
  var sectionRegex = new RegExp("<!--".concat(sectionName, "-->([\\s\\S]*?)<!--/").concat(sectionName, "-->"), 'g');
5840
5869
  var sectionMatch = content.match(sectionRegex);
5870
+ var contentToInsert = spaceTrim$1(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); });
5841
5871
  if (sectionMatch) {
5842
- return content.replace(sectionRegex, spaceTrim$1(function (block) { return "\n <!--".concat(sectionName, "-->\n ").concat(block(warningLine), "\n ").concat(block(sectionContent), "\n <!--/").concat(sectionName, "-->\n "); }));
5872
+ return content.replace(sectionRegex, contentToInsert);
5843
5873
  }
5874
+ // Note: Following is the case when the section is not found in the file so we add it there
5844
5875
  var placeForSection = removeContentComments(content).match(/^##.*$/im);
5845
- if (!placeForSection) {
5846
- throw new ParseError(
5847
- // <- [🧠] Maybe something better tha `ParseError`
5848
- "No place where to put the section <!--".concat(sectionName, "-->"));
5849
- // <- [🚞]
5850
- }
5851
- var _a = __read(placeForSection, 1), heading = _a[0];
5852
- return content.replace(heading, "<!--".concat(sectionName, "-->\n").concat(warningLine, "\n").concat(sectionContent, "\n<!--/").concat(sectionName, "-->\n\n").concat(heading));
5876
+ if (placeForSection !== null) {
5877
+ var _a = __read(placeForSection, 1), heading_1 = _a[0];
5878
+ return content.replace(heading_1, spaceTrim$1(function (block) { return "\n ".concat(block(contentToInsert), "\n \n ").concat(block(heading_1), "\n "); }));
5879
+ }
5880
+ console.warn("No place where to put the section <!--".concat(sectionName, "-->, using the end of the file"));
5881
+ // <- TODO: [🚎] Some better way how to get warnings from pipeline parsing / logic
5882
+ return spaceTrim$1(function (block) { return "\n ".concat(block(content), "\n \n ").concat(block(contentToInsert), "\n "); });
5853
5883
  }
5854
5884
  /**
5855
5885
  * TODO: [🏛] This can be part of markdown builder