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