@promptbook/wizard 0.100.1 โ†’ 0.100.2

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
@@ -11,7 +11,7 @@ import { spawn } from 'child_process';
11
11
  import { forTime } from 'waitasecond';
12
12
  import { SHA256 } from 'crypto-js';
13
13
  import hexEncoder from 'crypto-js/enc-hex';
14
- import { basename, join, dirname, relative } from 'path';
14
+ import { basename, join, dirname, isAbsolute, relative } from 'path';
15
15
  import parserHtml from 'prettier/parser-html';
16
16
  import parserMarkdown from 'prettier/parser-markdown';
17
17
  import { format } from 'prettier/standalone';
@@ -39,7 +39,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
39
39
  * @generated
40
40
  * @see https://github.com/webgptorg/promptbook
41
41
  */
42
- const PROMPTBOOK_ENGINE_VERSION = '0.100.1';
42
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.2';
43
43
  /**
44
44
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
45
45
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -6217,7 +6217,7 @@ function removeEmojis(text) {
6217
6217
  }
6218
6218
 
6219
6219
  /**
6220
- * Tests if given string is valid URL.
6220
+ * Tests if given string is valid file path.
6221
6221
  *
6222
6222
  * Note: This does not check if the file exists only if the path is valid
6223
6223
  * @public exported from `@promptbook/utils`
@@ -6229,18 +6229,25 @@ function isValidFilePath(filename) {
6229
6229
  if (filename.split('\n').length > 1) {
6230
6230
  return false;
6231
6231
  }
6232
- if (filename.split(' ').length >
6233
- 5 /* <- TODO: [๐Ÿง ][๐Ÿˆท] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
6232
+ // Normalize slashes early so heuristics can detect path-like inputs
6233
+ const filenameSlashes = filename.replace(/\\/g, '/');
6234
+ // Reject strings that look like sentences (informational text)
6235
+ // Heuristic: contains multiple spaces and ends with a period, or contains typical sentence punctuation
6236
+ // But skip this heuristic if the string looks like a path (contains '/' or starts with a drive letter)
6237
+ if (filename.trim().length > 60 && // long enough to be a sentence
6238
+ /[.!?]/.test(filename) && // contains sentence punctuation
6239
+ filename.split(' ').length > 8 && // has many words
6240
+ !/\/|^[A-Z]:/i.test(filenameSlashes) // do NOT treat as sentence if looks like a path
6241
+ ) {
6234
6242
  return false;
6235
6243
  }
6236
- const filenameSlashes = filename.split('\\').join('/');
6237
6244
  // Absolute Unix path: /hello.txt
6238
6245
  if (/^(\/)/i.test(filenameSlashes)) {
6239
6246
  // console.log(filename, 'Absolute Unix path: /hello.txt');
6240
6247
  return true;
6241
6248
  }
6242
- // Absolute Windows path: /hello.txt
6243
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
6249
+ // Absolute Windows path: C:/ or C:\ (allow spaces and multiple dots in filename)
6250
+ if (/^[A-Z]:\/.+$/i.test(filenameSlashes)) {
6244
6251
  // console.log(filename, 'Absolute Windows path: /hello.txt');
6245
6252
  return true;
6246
6253
  }
@@ -8150,9 +8157,15 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
8150
8157
  }
8151
8158
  if (isValidUrl(knowledgeSourceContent)) {
8152
8159
  const url = knowledgeSourceContent;
8160
+ if (isVerbose) {
8161
+ console.info(`๐Ÿ“„ [1] "${name}" is available at "${url}"`);
8162
+ }
8153
8163
  const response = await fetch(url); // <- TODO: [๐Ÿง ] Scraping and fetch proxy
8154
8164
  const mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
8155
8165
  if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [๐Ÿ’ต] */)) {
8166
+ if (isVerbose) {
8167
+ console.info(`๐Ÿ“„ [2] "${name}" tools.fs is not available or URL is not a PDF.`);
8168
+ }
8156
8169
  return {
8157
8170
  source: name,
8158
8171
  filename: null,
@@ -8188,13 +8201,17 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
8188
8201
  await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
8189
8202
  }
8190
8203
  catch (error) {
8204
+ if (isVerbose) {
8205
+ console.info(`๐Ÿ“„ [3] "${name}" error creating cache directory`);
8206
+ }
8191
8207
  // Note: If we can't create cache directory, we'll handle it when trying to write the file
8192
8208
  // This handles read-only filesystems, permission issues, and missing parent directories
8193
- if (error instanceof Error && (error.message.includes('EROFS') ||
8194
- error.message.includes('read-only') ||
8195
- error.message.includes('EACCES') ||
8196
- error.message.includes('EPERM') ||
8197
- error.message.includes('ENOENT'))) ;
8209
+ if (error instanceof Error &&
8210
+ (error.message.includes('EROFS') ||
8211
+ error.message.includes('read-only') ||
8212
+ error.message.includes('EACCES') ||
8213
+ error.message.includes('EPERM') ||
8214
+ error.message.includes('ENOENT'))) ;
8198
8215
  else {
8199
8216
  // Re-throw other unexpected errors
8200
8217
  throw error;
@@ -8209,13 +8226,17 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
8209
8226
  await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
8210
8227
  }
8211
8228
  catch (error) {
8229
+ if (isVerbose) {
8230
+ console.info(`๐Ÿ“„ [4] "${name}" error writing cache file`);
8231
+ }
8212
8232
  // Note: If we can't write to cache, we'll process the file directly from memory
8213
8233
  // This handles read-only filesystems like Vercel
8214
- if (error instanceof Error && (error.message.includes('EROFS') ||
8215
- error.message.includes('read-only') ||
8216
- error.message.includes('EACCES') ||
8217
- error.message.includes('EPERM') ||
8218
- error.message.includes('ENOENT'))) {
8234
+ if (error instanceof Error &&
8235
+ (error.message.includes('EROFS') ||
8236
+ error.message.includes('read-only') ||
8237
+ error.message.includes('EACCES') ||
8238
+ error.message.includes('EPERM') ||
8239
+ error.message.includes('ENOENT'))) {
8219
8240
  // Return a handler that works directly with the downloaded content
8220
8241
  return {
8221
8242
  source: name,
@@ -8237,6 +8258,9 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
8237
8258
  }
8238
8259
  // TODO: [๐Ÿ’ต] Check the file security
8239
8260
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
8261
+ if (isVerbose) {
8262
+ console.info(`๐Ÿ“„ [5] "${name}" cached at "${join(rootDirname, filepath)}"`);
8263
+ }
8240
8264
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
8241
8265
  ...options,
8242
8266
  rootDirname,
@@ -8251,7 +8275,12 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
8251
8275
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
8252
8276
  // <- TODO: [๐Ÿง ] What is the best error type here`
8253
8277
  }
8254
- const filename = join(rootDirname, knowledgeSourceContent).split('\\').join('/');
8278
+ const filename = isAbsolute(knowledgeSourceContent)
8279
+ ? knowledgeSourceContent
8280
+ : join(rootDirname, knowledgeSourceContent).split('\\').join('/');
8281
+ if (isVerbose) {
8282
+ console.info(`๐Ÿ“„ [6] "${name}" is a valid file "${filename}"`);
8283
+ }
8255
8284
  const fileExtension = getFileExtension(filename);
8256
8285
  const mimeType = extensionToMimeType(fileExtension || '');
8257
8286
  if (!(await isFileExisting(filename, tools.fs))) {
@@ -8293,6 +8322,12 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
8293
8322
  };
8294
8323
  }
8295
8324
  else {
8325
+ if (isVerbose) {
8326
+ console.info(`๐Ÿ“„ [7] "${name}" is just a explicit string text with a knowledge source`);
8327
+ console.info('---');
8328
+ console.info(knowledgeSourceContent);
8329
+ console.info('---');
8330
+ }
8296
8331
  return {
8297
8332
  source: name,
8298
8333
  filename: null,