@promptbook/website-crawler 0.86.22 → 0.86.30

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.
@@ -2,7 +2,6 @@ import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
2
2
  import { VALUE_STRINGS } from '../config';
3
3
  import { SMALL_NUMBER } from '../config';
4
4
  import { renderPromptbookMermaid } from '../conversion/prettify/renderPipelineMermaidOptions';
5
- import { extractVariablesFromScript } from '../conversion/utils/extractVariablesFromScript';
6
5
  import { deserializeError } from '../errors/utils/deserializeError';
7
6
  import { serializeError } from '../errors/utils/serializeError';
8
7
  import { forEachAsync } from '../execution/utils/forEachAsync';
@@ -84,7 +83,6 @@ export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
84
83
  export { VALUE_STRINGS };
85
84
  export { SMALL_NUMBER };
86
85
  export { renderPromptbookMermaid };
87
- export { extractVariablesFromScript };
88
86
  export { deserializeError };
89
87
  export { serializeError };
90
88
  export { forEachAsync };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/website-crawler",
3
- "version": "0.86.22",
3
+ "version": "0.86.30",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -47,7 +47,7 @@
47
47
  "module": "./esm/index.es.js",
48
48
  "typings": "./esm/typings/src/_packages/website-crawler.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.86.22"
50
+ "@promptbook/core": "0.86.30"
51
51
  },
52
52
  "dependencies": {
53
53
  "@mozilla/readability": "0.5.0",
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.86.22';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.86.30';
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
@@ -3645,142 +3645,6 @@
3645
3645
  }
3646
3646
  }
3647
3647
 
3648
- /**
3649
- * Extract all used variable names from ginen JavaScript/TypeScript script
3650
- *
3651
- * @param script JavaScript/TypeScript script
3652
- * @returns Set of variable names
3653
- * @throws {ParseError} if the script is invalid
3654
- * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
3655
- */
3656
- function extractVariablesFromScript(script) {
3657
- if (script.trim() === '') {
3658
- return new Set();
3659
- }
3660
- const variables = new Set();
3661
- // JS keywords and builtins to exclude
3662
- const exclude = new Set([
3663
- // Keywords
3664
- 'break',
3665
- 'case',
3666
- 'catch',
3667
- 'class',
3668
- 'const',
3669
- 'continue',
3670
- 'debugger',
3671
- 'default',
3672
- 'delete',
3673
- 'do',
3674
- 'else',
3675
- 'export',
3676
- 'extends',
3677
- 'false',
3678
- 'finally',
3679
- 'for',
3680
- 'function',
3681
- 'if',
3682
- 'import',
3683
- 'in',
3684
- 'instanceof',
3685
- 'let',
3686
- 'new',
3687
- 'null',
3688
- 'return',
3689
- 'super',
3690
- 'switch',
3691
- 'this',
3692
- 'throw',
3693
- 'true',
3694
- 'try',
3695
- 'typeof',
3696
- 'var',
3697
- 'void',
3698
- 'while',
3699
- 'with',
3700
- 'yield',
3701
- // Common globals
3702
- 'console',
3703
- 'JSON',
3704
- 'Error',
3705
- // Typescript types
3706
- 'string',
3707
- 'number',
3708
- 'boolean',
3709
- 'object',
3710
- 'symbol',
3711
- // Common methods on built-in objects
3712
- 'test',
3713
- 'match',
3714
- 'exec',
3715
- 'replace',
3716
- 'search',
3717
- 'split',
3718
- ]);
3719
- try {
3720
- // Note: Extract variables from template literals like ${variable}
3721
- const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
3722
- let match;
3723
- while ((match = templateRegex.exec(script)) !== null) {
3724
- const varName = match[1];
3725
- if (!exclude.has(varName)) {
3726
- variables.add(varName);
3727
- }
3728
- }
3729
- // Note: Process the script to handle normal variable usage
3730
- const processedScript = script
3731
- .replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
3732
- .replace(/"(?:\\.|[^"\\])*"/g, '""')
3733
- .replace(/`(?:\\.|[^`\\])*`/g, '``')
3734
- .replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
3735
- // Note: Find identifiers in function arguments
3736
- const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
3737
- const funcNames = new Set();
3738
- while ((match = funcArgRegex.exec(processedScript)) !== null) {
3739
- funcNames.add(match[1]);
3740
- }
3741
- // Find variable declarations to exclude them
3742
- const declaredVars = new Set();
3743
- const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
3744
- while ((match = declRegex.exec(processedScript)) !== null) {
3745
- declaredVars.add(match[2]);
3746
- }
3747
- // Note: Find identifiers in the script
3748
- const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
3749
- while ((match = identifierRegex.exec(processedScript)) !== null) {
3750
- const name = match[1];
3751
- // Add if not excluded, not a function name, and not a declared variable
3752
- if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
3753
- variables.add(name);
3754
- }
3755
- }
3756
- }
3757
- catch (error) {
3758
- if (!(error instanceof Error)) {
3759
- throw error;
3760
- }
3761
- throw new ParseError(spaceTrim__default["default"]((block) => `
3762
- Can not extract variables from the script
3763
- ${block(error.stack || error.message)}
3764
-
3765
- Found variables:
3766
- ${Array.from(variables)
3767
- .map((variableName, i) => `${i + 1}) ${variableName}`)
3768
- .join('\n')}
3769
-
3770
-
3771
- The script:
3772
-
3773
- \`\`\`javascript
3774
- ${block(script)}
3775
- \`\`\`
3776
- `));
3777
- }
3778
- return variables;
3779
- }
3780
- /**
3781
- * TODO: [🔣] Support for multiple languages - python, java,...
3782
- */
3783
-
3784
3648
  /**
3785
3649
  * Parses the task and returns the set of all used parameters
3786
3650
  *
@@ -3790,7 +3654,7 @@
3790
3654
  * @public exported from `@promptbook/core` <- Note: [👖] This utility is so tightly interconnected with the Promptbook that it is not exported as util but in core
3791
3655
  */
3792
3656
  function extractParameterNamesFromTask(task) {
3793
- const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
3657
+ const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
3794
3658
  const parameterNames = new Set();
3795
3659
  for (const parameterName of [
3796
3660
  ...extractParameterNames(title),
@@ -3800,11 +3664,14 @@
3800
3664
  ]) {
3801
3665
  parameterNames.add(parameterName);
3802
3666
  }
3667
+ /*/
3668
+ // TODO: [🙊] Fix `extractVariablesFromScript` or delete
3803
3669
  if (taskType === 'SCRIPT_TASK') {
3804
3670
  for (const parameterName of extractVariablesFromScript(content)) {
3805
3671
  parameterNames.add(parameterName);
3806
3672
  }
3807
3673
  }
3674
+ /**/
3808
3675
  for (const jokerName of jokerParameterNames || []) {
3809
3676
  parameterNames.add(jokerName);
3810
3677
  }