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