@promptbook/markdown-utils 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 +1 -1
- 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
|
@@ -25,7 +25,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.86.
|
|
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
|
|
@@ -3720,142 +3720,6 @@ function valueToString(value) {
|
|
|
3720
3720
|
}
|
|
3721
3721
|
}
|
|
3722
3722
|
|
|
3723
|
-
/**
|
|
3724
|
-
* Extract all used variable names from ginen JavaScript/TypeScript script
|
|
3725
|
-
*
|
|
3726
|
-
* @param script JavaScript/TypeScript script
|
|
3727
|
-
* @returns Set of variable names
|
|
3728
|
-
* @throws {ParseError} if the script is invalid
|
|
3729
|
-
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
3730
|
-
*/
|
|
3731
|
-
function extractVariablesFromScript(script) {
|
|
3732
|
-
if (script.trim() === '') {
|
|
3733
|
-
return new Set();
|
|
3734
|
-
}
|
|
3735
|
-
const variables = new Set();
|
|
3736
|
-
// JS keywords and builtins to exclude
|
|
3737
|
-
const exclude = new Set([
|
|
3738
|
-
// Keywords
|
|
3739
|
-
'break',
|
|
3740
|
-
'case',
|
|
3741
|
-
'catch',
|
|
3742
|
-
'class',
|
|
3743
|
-
'const',
|
|
3744
|
-
'continue',
|
|
3745
|
-
'debugger',
|
|
3746
|
-
'default',
|
|
3747
|
-
'delete',
|
|
3748
|
-
'do',
|
|
3749
|
-
'else',
|
|
3750
|
-
'export',
|
|
3751
|
-
'extends',
|
|
3752
|
-
'false',
|
|
3753
|
-
'finally',
|
|
3754
|
-
'for',
|
|
3755
|
-
'function',
|
|
3756
|
-
'if',
|
|
3757
|
-
'import',
|
|
3758
|
-
'in',
|
|
3759
|
-
'instanceof',
|
|
3760
|
-
'let',
|
|
3761
|
-
'new',
|
|
3762
|
-
'null',
|
|
3763
|
-
'return',
|
|
3764
|
-
'super',
|
|
3765
|
-
'switch',
|
|
3766
|
-
'this',
|
|
3767
|
-
'throw',
|
|
3768
|
-
'true',
|
|
3769
|
-
'try',
|
|
3770
|
-
'typeof',
|
|
3771
|
-
'var',
|
|
3772
|
-
'void',
|
|
3773
|
-
'while',
|
|
3774
|
-
'with',
|
|
3775
|
-
'yield',
|
|
3776
|
-
// Common globals
|
|
3777
|
-
'console',
|
|
3778
|
-
'JSON',
|
|
3779
|
-
'Error',
|
|
3780
|
-
// Typescript types
|
|
3781
|
-
'string',
|
|
3782
|
-
'number',
|
|
3783
|
-
'boolean',
|
|
3784
|
-
'object',
|
|
3785
|
-
'symbol',
|
|
3786
|
-
// Common methods on built-in objects
|
|
3787
|
-
'test',
|
|
3788
|
-
'match',
|
|
3789
|
-
'exec',
|
|
3790
|
-
'replace',
|
|
3791
|
-
'search',
|
|
3792
|
-
'split',
|
|
3793
|
-
]);
|
|
3794
|
-
try {
|
|
3795
|
-
// Note: Extract variables from template literals like ${variable}
|
|
3796
|
-
const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
|
|
3797
|
-
let match;
|
|
3798
|
-
while ((match = templateRegex.exec(script)) !== null) {
|
|
3799
|
-
const varName = match[1];
|
|
3800
|
-
if (!exclude.has(varName)) {
|
|
3801
|
-
variables.add(varName);
|
|
3802
|
-
}
|
|
3803
|
-
}
|
|
3804
|
-
// Note: Process the script to handle normal variable usage
|
|
3805
|
-
const processedScript = script
|
|
3806
|
-
.replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
|
|
3807
|
-
.replace(/"(?:\\.|[^"\\])*"/g, '""')
|
|
3808
|
-
.replace(/`(?:\\.|[^`\\])*`/g, '``')
|
|
3809
|
-
.replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
|
|
3810
|
-
// Note: Find identifiers in function arguments
|
|
3811
|
-
const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
|
|
3812
|
-
const funcNames = new Set();
|
|
3813
|
-
while ((match = funcArgRegex.exec(processedScript)) !== null) {
|
|
3814
|
-
funcNames.add(match[1]);
|
|
3815
|
-
}
|
|
3816
|
-
// Find variable declarations to exclude them
|
|
3817
|
-
const declaredVars = new Set();
|
|
3818
|
-
const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
3819
|
-
while ((match = declRegex.exec(processedScript)) !== null) {
|
|
3820
|
-
declaredVars.add(match[2]);
|
|
3821
|
-
}
|
|
3822
|
-
// Note: Find identifiers in the script
|
|
3823
|
-
const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
3824
|
-
while ((match = identifierRegex.exec(processedScript)) !== null) {
|
|
3825
|
-
const name = match[1];
|
|
3826
|
-
// Add if not excluded, not a function name, and not a declared variable
|
|
3827
|
-
if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
|
|
3828
|
-
variables.add(name);
|
|
3829
|
-
}
|
|
3830
|
-
}
|
|
3831
|
-
}
|
|
3832
|
-
catch (error) {
|
|
3833
|
-
if (!(error instanceof Error)) {
|
|
3834
|
-
throw error;
|
|
3835
|
-
}
|
|
3836
|
-
throw new ParseError(spaceTrim((block) => `
|
|
3837
|
-
Can not extract variables from the script
|
|
3838
|
-
${block(error.stack || error.message)}
|
|
3839
|
-
|
|
3840
|
-
Found variables:
|
|
3841
|
-
${Array.from(variables)
|
|
3842
|
-
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
3843
|
-
.join('\n')}
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
The script:
|
|
3847
|
-
|
|
3848
|
-
\`\`\`javascript
|
|
3849
|
-
${block(script)}
|
|
3850
|
-
\`\`\`
|
|
3851
|
-
`));
|
|
3852
|
-
}
|
|
3853
|
-
return variables;
|
|
3854
|
-
}
|
|
3855
|
-
/**
|
|
3856
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
3857
|
-
*/
|
|
3858
|
-
|
|
3859
3723
|
/**
|
|
3860
3724
|
* Parses the task and returns the set of all used parameters
|
|
3861
3725
|
*
|
|
@@ -3865,7 +3729,7 @@ function extractVariablesFromScript(script) {
|
|
|
3865
3729
|
* @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
|
|
3866
3730
|
*/
|
|
3867
3731
|
function extractParameterNamesFromTask(task) {
|
|
3868
|
-
const { title, description, taskType
|
|
3732
|
+
const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
|
|
3869
3733
|
const parameterNames = new Set();
|
|
3870
3734
|
for (const parameterName of [
|
|
3871
3735
|
...extractParameterNames(title),
|
|
@@ -3875,11 +3739,14 @@ function extractParameterNamesFromTask(task) {
|
|
|
3875
3739
|
]) {
|
|
3876
3740
|
parameterNames.add(parameterName);
|
|
3877
3741
|
}
|
|
3742
|
+
/*/
|
|
3743
|
+
// TODO: [🙊] Fix `extractVariablesFromScript` or delete
|
|
3878
3744
|
if (taskType === 'SCRIPT_TASK') {
|
|
3879
3745
|
for (const parameterName of extractVariablesFromScript(content)) {
|
|
3880
3746
|
parameterNames.add(parameterName);
|
|
3881
3747
|
}
|
|
3882
3748
|
}
|
|
3749
|
+
/**/
|
|
3883
3750
|
for (const jokerName of jokerParameterNames || []) {
|
|
3884
3751
|
parameterNames.add(jokerName);
|
|
3885
3752
|
}
|