@promptbook/documents 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/documents",
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/documents.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
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -26,7 +26,7 @@
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
@@ -3793,142 +3793,6 @@
3793
3793
  }
3794
3794
  }
3795
3795
 
3796
- /**
3797
- * Extract all used variable names from ginen JavaScript/TypeScript script
3798
- *
3799
- * @param script JavaScript/TypeScript script
3800
- * @returns Set of variable names
3801
- * @throws {ParseError} if the script is invalid
3802
- * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
3803
- */
3804
- function extractVariablesFromScript(script) {
3805
- if (script.trim() === '') {
3806
- return new Set();
3807
- }
3808
- const variables = new Set();
3809
- // JS keywords and builtins to exclude
3810
- const exclude = new Set([
3811
- // Keywords
3812
- 'break',
3813
- 'case',
3814
- 'catch',
3815
- 'class',
3816
- 'const',
3817
- 'continue',
3818
- 'debugger',
3819
- 'default',
3820
- 'delete',
3821
- 'do',
3822
- 'else',
3823
- 'export',
3824
- 'extends',
3825
- 'false',
3826
- 'finally',
3827
- 'for',
3828
- 'function',
3829
- 'if',
3830
- 'import',
3831
- 'in',
3832
- 'instanceof',
3833
- 'let',
3834
- 'new',
3835
- 'null',
3836
- 'return',
3837
- 'super',
3838
- 'switch',
3839
- 'this',
3840
- 'throw',
3841
- 'true',
3842
- 'try',
3843
- 'typeof',
3844
- 'var',
3845
- 'void',
3846
- 'while',
3847
- 'with',
3848
- 'yield',
3849
- // Common globals
3850
- 'console',
3851
- 'JSON',
3852
- 'Error',
3853
- // Typescript types
3854
- 'string',
3855
- 'number',
3856
- 'boolean',
3857
- 'object',
3858
- 'symbol',
3859
- // Common methods on built-in objects
3860
- 'test',
3861
- 'match',
3862
- 'exec',
3863
- 'replace',
3864
- 'search',
3865
- 'split',
3866
- ]);
3867
- try {
3868
- // Note: Extract variables from template literals like ${variable}
3869
- const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
3870
- let match;
3871
- while ((match = templateRegex.exec(script)) !== null) {
3872
- const varName = match[1];
3873
- if (!exclude.has(varName)) {
3874
- variables.add(varName);
3875
- }
3876
- }
3877
- // Note: Process the script to handle normal variable usage
3878
- const processedScript = script
3879
- .replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
3880
- .replace(/"(?:\\.|[^"\\])*"/g, '""')
3881
- .replace(/`(?:\\.|[^`\\])*`/g, '``')
3882
- .replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
3883
- // Note: Find identifiers in function arguments
3884
- const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
3885
- const funcNames = new Set();
3886
- while ((match = funcArgRegex.exec(processedScript)) !== null) {
3887
- funcNames.add(match[1]);
3888
- }
3889
- // Find variable declarations to exclude them
3890
- const declaredVars = new Set();
3891
- const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
3892
- while ((match = declRegex.exec(processedScript)) !== null) {
3893
- declaredVars.add(match[2]);
3894
- }
3895
- // Note: Find identifiers in the script
3896
- const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
3897
- while ((match = identifierRegex.exec(processedScript)) !== null) {
3898
- const name = match[1];
3899
- // Add if not excluded, not a function name, and not a declared variable
3900
- if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
3901
- variables.add(name);
3902
- }
3903
- }
3904
- }
3905
- catch (error) {
3906
- if (!(error instanceof Error)) {
3907
- throw error;
3908
- }
3909
- throw new ParseError(spaceTrim__default["default"]((block) => `
3910
- Can not extract variables from the script
3911
- ${block(error.stack || error.message)}
3912
-
3913
- Found variables:
3914
- ${Array.from(variables)
3915
- .map((variableName, i) => `${i + 1}) ${variableName}`)
3916
- .join('\n')}
3917
-
3918
-
3919
- The script:
3920
-
3921
- \`\`\`javascript
3922
- ${block(script)}
3923
- \`\`\`
3924
- `));
3925
- }
3926
- return variables;
3927
- }
3928
- /**
3929
- * TODO: [🔣] Support for multiple languages - python, java,...
3930
- */
3931
-
3932
3796
  /**
3933
3797
  * Parses the task and returns the set of all used parameters
3934
3798
  *
@@ -3938,7 +3802,7 @@
3938
3802
  * @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
3939
3803
  */
3940
3804
  function extractParameterNamesFromTask(task) {
3941
- const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
3805
+ const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
3942
3806
  const parameterNames = new Set();
3943
3807
  for (const parameterName of [
3944
3808
  ...extractParameterNames(title),
@@ -3948,11 +3812,14 @@
3948
3812
  ]) {
3949
3813
  parameterNames.add(parameterName);
3950
3814
  }
3815
+ /*/
3816
+ // TODO: [🙊] Fix `extractVariablesFromScript` or delete
3951
3817
  if (taskType === 'SCRIPT_TASK') {
3952
3818
  for (const parameterName of extractVariablesFromScript(content)) {
3953
3819
  parameterNames.add(parameterName);
3954
3820
  }
3955
3821
  }
3822
+ /**/
3956
3823
  for (const jokerName of jokerParameterNames || []) {
3957
3824
  parameterNames.add(jokerName);
3958
3825
  }