@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.
package/esm/index.es.js CHANGED
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
29
29
  * @generated
30
30
  * @see https://github.com/webgptorg/promptbook
31
31
  */
32
- const PROMPTBOOK_ENGINE_VERSION = '0.86.22';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.86.30';
33
33
  /**
34
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
35
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -3649,142 +3649,6 @@ function valueToString(value) {
3649
3649
  }
3650
3650
  }
3651
3651
 
3652
- /**
3653
- * Extract all used variable names from ginen JavaScript/TypeScript script
3654
- *
3655
- * @param script JavaScript/TypeScript script
3656
- * @returns Set of variable names
3657
- * @throws {ParseError} if the script is invalid
3658
- * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
3659
- */
3660
- function extractVariablesFromScript(script) {
3661
- if (script.trim() === '') {
3662
- return new Set();
3663
- }
3664
- const variables = new Set();
3665
- // JS keywords and builtins to exclude
3666
- const exclude = new Set([
3667
- // Keywords
3668
- 'break',
3669
- 'case',
3670
- 'catch',
3671
- 'class',
3672
- 'const',
3673
- 'continue',
3674
- 'debugger',
3675
- 'default',
3676
- 'delete',
3677
- 'do',
3678
- 'else',
3679
- 'export',
3680
- 'extends',
3681
- 'false',
3682
- 'finally',
3683
- 'for',
3684
- 'function',
3685
- 'if',
3686
- 'import',
3687
- 'in',
3688
- 'instanceof',
3689
- 'let',
3690
- 'new',
3691
- 'null',
3692
- 'return',
3693
- 'super',
3694
- 'switch',
3695
- 'this',
3696
- 'throw',
3697
- 'true',
3698
- 'try',
3699
- 'typeof',
3700
- 'var',
3701
- 'void',
3702
- 'while',
3703
- 'with',
3704
- 'yield',
3705
- // Common globals
3706
- 'console',
3707
- 'JSON',
3708
- 'Error',
3709
- // Typescript types
3710
- 'string',
3711
- 'number',
3712
- 'boolean',
3713
- 'object',
3714
- 'symbol',
3715
- // Common methods on built-in objects
3716
- 'test',
3717
- 'match',
3718
- 'exec',
3719
- 'replace',
3720
- 'search',
3721
- 'split',
3722
- ]);
3723
- try {
3724
- // Note: Extract variables from template literals like ${variable}
3725
- const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
3726
- let match;
3727
- while ((match = templateRegex.exec(script)) !== null) {
3728
- const varName = match[1];
3729
- if (!exclude.has(varName)) {
3730
- variables.add(varName);
3731
- }
3732
- }
3733
- // Note: Process the script to handle normal variable usage
3734
- const processedScript = script
3735
- .replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
3736
- .replace(/"(?:\\.|[^"\\])*"/g, '""')
3737
- .replace(/`(?:\\.|[^`\\])*`/g, '``')
3738
- .replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
3739
- // Note: Find identifiers in function arguments
3740
- const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
3741
- const funcNames = new Set();
3742
- while ((match = funcArgRegex.exec(processedScript)) !== null) {
3743
- funcNames.add(match[1]);
3744
- }
3745
- // Find variable declarations to exclude them
3746
- const declaredVars = new Set();
3747
- const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
3748
- while ((match = declRegex.exec(processedScript)) !== null) {
3749
- declaredVars.add(match[2]);
3750
- }
3751
- // Note: Find identifiers in the script
3752
- const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
3753
- while ((match = identifierRegex.exec(processedScript)) !== null) {
3754
- const name = match[1];
3755
- // Add if not excluded, not a function name, and not a declared variable
3756
- if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
3757
- variables.add(name);
3758
- }
3759
- }
3760
- }
3761
- catch (error) {
3762
- if (!(error instanceof Error)) {
3763
- throw error;
3764
- }
3765
- throw new ParseError(spaceTrim$1((block) => `
3766
- Can not extract variables from the script
3767
- ${block(error.stack || error.message)}
3768
-
3769
- Found variables:
3770
- ${Array.from(variables)
3771
- .map((variableName, i) => `${i + 1}) ${variableName}`)
3772
- .join('\n')}
3773
-
3774
-
3775
- The script:
3776
-
3777
- \`\`\`javascript
3778
- ${block(script)}
3779
- \`\`\`
3780
- `));
3781
- }
3782
- return variables;
3783
- }
3784
- /**
3785
- * TODO: [🔣] Support for multiple languages - python, java,...
3786
- */
3787
-
3788
3652
  /**
3789
3653
  * Parses the task and returns the set of all used parameters
3790
3654
  *
@@ -3794,7 +3658,7 @@ function extractVariablesFromScript(script) {
3794
3658
  * @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
3795
3659
  */
3796
3660
  function extractParameterNamesFromTask(task) {
3797
- const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
3661
+ const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
3798
3662
  const parameterNames = new Set();
3799
3663
  for (const parameterName of [
3800
3664
  ...extractParameterNames(title),
@@ -3804,11 +3668,14 @@ function extractParameterNamesFromTask(task) {
3804
3668
  ]) {
3805
3669
  parameterNames.add(parameterName);
3806
3670
  }
3671
+ /*/
3672
+ // TODO: [🙊] Fix `extractVariablesFromScript` or delete
3807
3673
  if (taskType === 'SCRIPT_TASK') {
3808
3674
  for (const parameterName of extractVariablesFromScript(content)) {
3809
3675
  parameterNames.add(parameterName);
3810
3676
  }
3811
3677
  }
3678
+ /**/
3812
3679
  for (const jokerName of jokerParameterNames || []) {
3813
3680
  parameterNames.add(jokerName);
3814
3681
  }