@promptbook/cli 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
@@ -3,7 +3,7 @@ import commander from 'commander';
3
3
  import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
4
4
  import { forTime, forEver } from 'waitasecond';
5
5
  import prompts from 'prompts';
6
- import { join, basename, dirname, relative } from 'path';
6
+ import { join, basename, dirname, isAbsolute, relative } from 'path';
7
7
  import { stat, access, constants, readFile, writeFile, readdir, mkdir, unlink, rm, rename, rmdir } from 'fs/promises';
8
8
  import * as dotenv from 'dotenv';
9
9
  import hexEncoder from 'crypto-js/enc-hex';
@@ -48,7 +48,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
48
48
  * @generated
49
49
  * @see https://github.com/webgptorg/promptbook
50
50
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.100.1';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.2';
52
52
  /**
53
53
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
54
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -1736,7 +1736,7 @@ function removeEmojis(text) {
1736
1736
  }
1737
1737
 
1738
1738
  /**
1739
- * Tests if given string is valid URL.
1739
+ * Tests if given string is valid file path.
1740
1740
  *
1741
1741
  * Note: This does not check if the file exists only if the path is valid
1742
1742
  * @public exported from `@promptbook/utils`
@@ -1748,18 +1748,25 @@ function isValidFilePath(filename) {
1748
1748
  if (filename.split('\n').length > 1) {
1749
1749
  return false;
1750
1750
  }
1751
- if (filename.split(' ').length >
1752
- 5 /* <- TODO: [๐Ÿง ][๐Ÿˆท] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
1751
+ // Normalize slashes early so heuristics can detect path-like inputs
1752
+ const filenameSlashes = filename.replace(/\\/g, '/');
1753
+ // Reject strings that look like sentences (informational text)
1754
+ // Heuristic: contains multiple spaces and ends with a period, or contains typical sentence punctuation
1755
+ // But skip this heuristic if the string looks like a path (contains '/' or starts with a drive letter)
1756
+ if (filename.trim().length > 60 && // long enough to be a sentence
1757
+ /[.!?]/.test(filename) && // contains sentence punctuation
1758
+ filename.split(' ').length > 8 && // has many words
1759
+ !/\/|^[A-Z]:/i.test(filenameSlashes) // do NOT treat as sentence if looks like a path
1760
+ ) {
1753
1761
  return false;
1754
1762
  }
1755
- const filenameSlashes = filename.split('\\').join('/');
1756
1763
  // Absolute Unix path: /hello.txt
1757
1764
  if (/^(\/)/i.test(filenameSlashes)) {
1758
1765
  // console.log(filename, 'Absolute Unix path: /hello.txt');
1759
1766
  return true;
1760
1767
  }
1761
- // Absolute Windows path: /hello.txt
1762
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
1768
+ // Absolute Windows path: C:/ or C:\ (allow spaces and multiple dots in filename)
1769
+ if (/^[A-Z]:\/.+$/i.test(filenameSlashes)) {
1763
1770
  // console.log(filename, 'Absolute Windows path: /hello.txt');
1764
1771
  return true;
1765
1772
  }
@@ -7918,9 +7925,15 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
7918
7925
  }
7919
7926
  if (isValidUrl(knowledgeSourceContent)) {
7920
7927
  const url = knowledgeSourceContent;
7928
+ if (isVerbose) {
7929
+ console.info(`๐Ÿ“„ [1] "${name}" is available at "${url}"`);
7930
+ }
7921
7931
  const response = await fetch(url); // <- TODO: [๐Ÿง ] Scraping and fetch proxy
7922
7932
  const mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
7923
7933
  if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [๐Ÿ’ต] */)) {
7934
+ if (isVerbose) {
7935
+ console.info(`๐Ÿ“„ [2] "${name}" tools.fs is not available or URL is not a PDF.`);
7936
+ }
7924
7937
  return {
7925
7938
  source: name,
7926
7939
  filename: null,
@@ -7956,13 +7969,17 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
7956
7969
  await tools.fs.mkdir(dirname(join(rootDirname, filepath)), { recursive: true });
7957
7970
  }
7958
7971
  catch (error) {
7972
+ if (isVerbose) {
7973
+ console.info(`๐Ÿ“„ [3] "${name}" error creating cache directory`);
7974
+ }
7959
7975
  // Note: If we can't create cache directory, we'll handle it when trying to write the file
7960
7976
  // This handles read-only filesystems, permission issues, and missing parent directories
7961
- if (error instanceof Error && (error.message.includes('EROFS') ||
7962
- error.message.includes('read-only') ||
7963
- error.message.includes('EACCES') ||
7964
- error.message.includes('EPERM') ||
7965
- error.message.includes('ENOENT'))) ;
7977
+ if (error instanceof Error &&
7978
+ (error.message.includes('EROFS') ||
7979
+ error.message.includes('read-only') ||
7980
+ error.message.includes('EACCES') ||
7981
+ error.message.includes('EPERM') ||
7982
+ error.message.includes('ENOENT'))) ;
7966
7983
  else {
7967
7984
  // Re-throw other unexpected errors
7968
7985
  throw error;
@@ -7977,13 +7994,17 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
7977
7994
  await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
7978
7995
  }
7979
7996
  catch (error) {
7997
+ if (isVerbose) {
7998
+ console.info(`๐Ÿ“„ [4] "${name}" error writing cache file`);
7999
+ }
7980
8000
  // Note: If we can't write to cache, we'll process the file directly from memory
7981
8001
  // This handles read-only filesystems like Vercel
7982
- if (error instanceof Error && (error.message.includes('EROFS') ||
7983
- error.message.includes('read-only') ||
7984
- error.message.includes('EACCES') ||
7985
- error.message.includes('EPERM') ||
7986
- error.message.includes('ENOENT'))) {
8002
+ if (error instanceof Error &&
8003
+ (error.message.includes('EROFS') ||
8004
+ error.message.includes('read-only') ||
8005
+ error.message.includes('EACCES') ||
8006
+ error.message.includes('EPERM') ||
8007
+ error.message.includes('ENOENT'))) {
7987
8008
  // Return a handler that works directly with the downloaded content
7988
8009
  return {
7989
8010
  source: name,
@@ -8005,6 +8026,9 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
8005
8026
  }
8006
8027
  // TODO: [๐Ÿ’ต] Check the file security
8007
8028
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
8029
+ if (isVerbose) {
8030
+ console.info(`๐Ÿ“„ [5] "${name}" cached at "${join(rootDirname, filepath)}"`);
8031
+ }
8008
8032
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
8009
8033
  ...options,
8010
8034
  rootDirname,
@@ -8019,7 +8043,12 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
8019
8043
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
8020
8044
  // <- TODO: [๐Ÿง ] What is the best error type here`
8021
8045
  }
8022
- const filename = join(rootDirname, knowledgeSourceContent).split('\\').join('/');
8046
+ const filename = isAbsolute(knowledgeSourceContent)
8047
+ ? knowledgeSourceContent
8048
+ : join(rootDirname, knowledgeSourceContent).split('\\').join('/');
8049
+ if (isVerbose) {
8050
+ console.info(`๐Ÿ“„ [6] "${name}" is a valid file "${filename}"`);
8051
+ }
8023
8052
  const fileExtension = getFileExtension(filename);
8024
8053
  const mimeType = extensionToMimeType(fileExtension || '');
8025
8054
  if (!(await isFileExisting(filename, tools.fs))) {
@@ -8061,6 +8090,12 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
8061
8090
  };
8062
8091
  }
8063
8092
  else {
8093
+ if (isVerbose) {
8094
+ console.info(`๐Ÿ“„ [7] "${name}" is just a explicit string text with a knowledge source`);
8095
+ console.info('---');
8096
+ console.info(knowledgeSourceContent);
8097
+ console.info('---');
8098
+ }
8064
8099
  return {
8065
8100
  source: name,
8066
8101
  filename: null,