@promptbook/pdf 0.86.22 → 0.86.31
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 +55 -109
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/execute-javascript.index.d.ts +2 -0
- package/esm/typings/src/_packages/utils.index.d.ts +0 -2
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.d.ts +14 -0
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromScript.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +55 -109
- 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 → scripting/javascript/utils/extractVariablesFromJavascript.test.d.ts} +0 -0
|
@@ -2,7 +2,9 @@ import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
|
|
|
2
2
|
import { JavascriptEvalExecutionTools } from '../scripting/javascript/JavascriptEvalExecutionTools';
|
|
3
3
|
import { JavascriptExecutionTools } from '../scripting/javascript/JavascriptExecutionTools';
|
|
4
4
|
import { POSTPROCESSING_FUNCTIONS } from '../scripting/javascript/postprocessing-functions';
|
|
5
|
+
import { extractVariablesFromJavascript } from '../scripting/javascript/utils/extractVariablesFromJavascript';
|
|
5
6
|
export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
|
|
6
7
|
export { JavascriptEvalExecutionTools };
|
|
7
8
|
export { JavascriptExecutionTools };
|
|
8
9
|
export { POSTPROCESSING_FUNCTIONS };
|
|
10
|
+
export { extractVariablesFromJavascript };
|
|
@@ -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 };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { string_javascript } from '../../../types/typeAliases';
|
|
2
|
+
import type { string_javascript_name } from '../../../types/typeAliases';
|
|
3
|
+
/**
|
|
4
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
5
|
+
*
|
|
6
|
+
* @param script from which to extract the variables
|
|
7
|
+
* @returns the list of variable names
|
|
8
|
+
* @throws {ParseError} if the script is invalid
|
|
9
|
+
* @public exported from `@promptbook/execute-javascript`
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractVariablesFromJavascript(script: string_javascript): Set<string_javascript_name>;
|
|
12
|
+
/**
|
|
13
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
14
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/pdf",
|
|
3
|
-
"version": "0.86.
|
|
3
|
+
"version": "0.86.31",
|
|
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/pdf.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.86.
|
|
50
|
+
"@promptbook/core": "0.86.31"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"crypto": "^1.0.1",
|
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
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.31';
|
|
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
|
|
@@ -3648,119 +3648,60 @@
|
|
|
3648
3648
|
}
|
|
3649
3649
|
|
|
3650
3650
|
/**
|
|
3651
|
-
*
|
|
3651
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
3652
3652
|
*
|
|
3653
|
-
* @param script
|
|
3654
|
-
* @returns
|
|
3653
|
+
* @param script from which to extract the variables
|
|
3654
|
+
* @returns the list of variable names
|
|
3655
3655
|
* @throws {ParseError} if the script is invalid
|
|
3656
|
-
* @public exported from `@promptbook/
|
|
3656
|
+
* @public exported from `@promptbook/execute-javascript`
|
|
3657
3657
|
*/
|
|
3658
|
-
function
|
|
3659
|
-
if (script.trim() === '') {
|
|
3660
|
-
return new Set();
|
|
3661
|
-
}
|
|
3658
|
+
function extractVariablesFromJavascript(script) {
|
|
3662
3659
|
const variables = new Set();
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
// Keywords
|
|
3666
|
-
'break',
|
|
3667
|
-
'case',
|
|
3668
|
-
'catch',
|
|
3669
|
-
'class',
|
|
3670
|
-
'const',
|
|
3671
|
-
'continue',
|
|
3672
|
-
'debugger',
|
|
3673
|
-
'default',
|
|
3674
|
-
'delete',
|
|
3675
|
-
'do',
|
|
3676
|
-
'else',
|
|
3677
|
-
'export',
|
|
3678
|
-
'extends',
|
|
3679
|
-
'false',
|
|
3680
|
-
'finally',
|
|
3681
|
-
'for',
|
|
3682
|
-
'function',
|
|
3683
|
-
'if',
|
|
3684
|
-
'import',
|
|
3685
|
-
'in',
|
|
3686
|
-
'instanceof',
|
|
3687
|
-
'let',
|
|
3688
|
-
'new',
|
|
3689
|
-
'null',
|
|
3690
|
-
'return',
|
|
3691
|
-
'super',
|
|
3692
|
-
'switch',
|
|
3693
|
-
'this',
|
|
3694
|
-
'throw',
|
|
3695
|
-
'true',
|
|
3696
|
-
'try',
|
|
3697
|
-
'typeof',
|
|
3698
|
-
'var',
|
|
3699
|
-
'void',
|
|
3700
|
-
'while',
|
|
3701
|
-
'with',
|
|
3702
|
-
'yield',
|
|
3703
|
-
// Common globals
|
|
3704
|
-
'console',
|
|
3705
|
-
'JSON',
|
|
3706
|
-
'Error',
|
|
3707
|
-
// Typescript types
|
|
3708
|
-
'string',
|
|
3709
|
-
'number',
|
|
3710
|
-
'boolean',
|
|
3711
|
-
'object',
|
|
3712
|
-
'symbol',
|
|
3713
|
-
// Common methods on built-in objects
|
|
3714
|
-
'test',
|
|
3715
|
-
'match',
|
|
3716
|
-
'exec',
|
|
3717
|
-
'replace',
|
|
3718
|
-
'search',
|
|
3719
|
-
'split',
|
|
3720
|
-
]);
|
|
3660
|
+
const originalScript = script;
|
|
3661
|
+
script = `(()=>{${script}})()`;
|
|
3721
3662
|
try {
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
while ((match = templateRegex.exec(script)) !== null) {
|
|
3726
|
-
const varName = match[1];
|
|
3727
|
-
if (!exclude.has(varName)) {
|
|
3728
|
-
variables.add(varName);
|
|
3663
|
+
for (let i = 0; i < LOOP_LIMIT; i++)
|
|
3664
|
+
try {
|
|
3665
|
+
eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
|
|
3729
3666
|
}
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3667
|
+
catch (error) {
|
|
3668
|
+
if (!(error instanceof ReferenceError)) {
|
|
3669
|
+
throw error;
|
|
3670
|
+
}
|
|
3671
|
+
/*
|
|
3672
|
+
Note: Parsing the error
|
|
3673
|
+
🌟 Most devices:
|
|
3674
|
+
[PipelineUrlError: thing is not defined]
|
|
3675
|
+
|
|
3676
|
+
🍏 iPhone`s Safari:
|
|
3677
|
+
[PipelineUrlError: Can't find variable: thing]
|
|
3678
|
+
*/
|
|
3679
|
+
let variableName = undefined;
|
|
3680
|
+
if (error.message.startsWith(`Can't`)) {
|
|
3681
|
+
// 🍏 Case
|
|
3682
|
+
variableName = error.message.split(' ').pop();
|
|
3683
|
+
}
|
|
3684
|
+
else {
|
|
3685
|
+
// 🌟 Case
|
|
3686
|
+
variableName = error.message.split(' ').shift();
|
|
3687
|
+
}
|
|
3688
|
+
if (variableName === undefined) {
|
|
3689
|
+
throw error;
|
|
3690
|
+
}
|
|
3691
|
+
if (script.includes(variableName + '(')) {
|
|
3692
|
+
script = `const ${variableName} = ()=>'';` + script;
|
|
3693
|
+
}
|
|
3694
|
+
else {
|
|
3695
|
+
variables.add(variableName);
|
|
3696
|
+
script = `const ${variableName} = '';` + script;
|
|
3697
|
+
}
|
|
3756
3698
|
}
|
|
3757
|
-
}
|
|
3758
3699
|
}
|
|
3759
3700
|
catch (error) {
|
|
3760
3701
|
if (!(error instanceof Error)) {
|
|
3761
3702
|
throw error;
|
|
3762
3703
|
}
|
|
3763
|
-
throw new ParseError(
|
|
3704
|
+
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
3764
3705
|
Can not extract variables from the script
|
|
3765
3706
|
${block(error.stack || error.message)}
|
|
3766
3707
|
|
|
@@ -3773,7 +3714,7 @@
|
|
|
3773
3714
|
The script:
|
|
3774
3715
|
|
|
3775
3716
|
\`\`\`javascript
|
|
3776
|
-
${block(
|
|
3717
|
+
${block(originalScript)}
|
|
3777
3718
|
\`\`\`
|
|
3778
3719
|
`));
|
|
3779
3720
|
}
|
|
@@ -3794,19 +3735,24 @@
|
|
|
3794
3735
|
function extractParameterNamesFromTask(task) {
|
|
3795
3736
|
const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
|
|
3796
3737
|
const parameterNames = new Set();
|
|
3738
|
+
let contentParameters;
|
|
3739
|
+
if (taskType !== 'SCRIPT_TASK') {
|
|
3740
|
+
contentParameters = extractParameterNames(content);
|
|
3741
|
+
}
|
|
3742
|
+
else {
|
|
3743
|
+
// TODO: What if script is not javascript?
|
|
3744
|
+
// const { contentLanguage } = task;
|
|
3745
|
+
// if (contentLanguage !== 'javascript') {
|
|
3746
|
+
contentParameters = extractVariablesFromJavascript(content);
|
|
3747
|
+
}
|
|
3797
3748
|
for (const parameterName of [
|
|
3798
3749
|
...extractParameterNames(title),
|
|
3799
3750
|
...extractParameterNames(description || ''),
|
|
3800
|
-
...
|
|
3751
|
+
...contentParameters,
|
|
3801
3752
|
...extractParameterNames(preparedContent || ''),
|
|
3802
3753
|
]) {
|
|
3803
3754
|
parameterNames.add(parameterName);
|
|
3804
3755
|
}
|
|
3805
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
3806
|
-
for (const parameterName of extractVariablesFromScript(content)) {
|
|
3807
|
-
parameterNames.add(parameterName);
|
|
3808
|
-
}
|
|
3809
|
-
}
|
|
3810
3756
|
for (const jokerName of jokerParameterNames || []) {
|
|
3811
3757
|
parameterNames.add(jokerName);
|
|
3812
3758
|
}
|