@promptbook/pdf 0.86.30 → 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 +90 -11
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/execute-javascript.index.d.ts +2 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.d.ts +14 -0
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.test.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromScript.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +90 -11
- package/umd/index.umd.js.map +1 -1
|
@@ -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 };
|
|
@@ -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 {};
|
|
@@ -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
|
|
@@ -3647,6 +3647,83 @@
|
|
|
3647
3647
|
}
|
|
3648
3648
|
}
|
|
3649
3649
|
|
|
3650
|
+
/**
|
|
3651
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
3652
|
+
*
|
|
3653
|
+
* @param script from which to extract the variables
|
|
3654
|
+
* @returns the list of variable names
|
|
3655
|
+
* @throws {ParseError} if the script is invalid
|
|
3656
|
+
* @public exported from `@promptbook/execute-javascript`
|
|
3657
|
+
*/
|
|
3658
|
+
function extractVariablesFromJavascript(script) {
|
|
3659
|
+
const variables = new Set();
|
|
3660
|
+
const originalScript = script;
|
|
3661
|
+
script = `(()=>{${script}})()`;
|
|
3662
|
+
try {
|
|
3663
|
+
for (let i = 0; i < LOOP_LIMIT; i++)
|
|
3664
|
+
try {
|
|
3665
|
+
eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
|
|
3666
|
+
}
|
|
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
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
catch (error) {
|
|
3701
|
+
if (!(error instanceof Error)) {
|
|
3702
|
+
throw error;
|
|
3703
|
+
}
|
|
3704
|
+
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
3705
|
+
Can not extract variables from the script
|
|
3706
|
+
${block(error.stack || error.message)}
|
|
3707
|
+
|
|
3708
|
+
Found variables:
|
|
3709
|
+
${Array.from(variables)
|
|
3710
|
+
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
3711
|
+
.join('\n')}
|
|
3712
|
+
|
|
3713
|
+
|
|
3714
|
+
The script:
|
|
3715
|
+
|
|
3716
|
+
\`\`\`javascript
|
|
3717
|
+
${block(originalScript)}
|
|
3718
|
+
\`\`\`
|
|
3719
|
+
`));
|
|
3720
|
+
}
|
|
3721
|
+
return variables;
|
|
3722
|
+
}
|
|
3723
|
+
/**
|
|
3724
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
3725
|
+
*/
|
|
3726
|
+
|
|
3650
3727
|
/**
|
|
3651
3728
|
* Parses the task and returns the set of all used parameters
|
|
3652
3729
|
*
|
|
@@ -3656,24 +3733,26 @@
|
|
|
3656
3733
|
* @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
|
|
3657
3734
|
*/
|
|
3658
3735
|
function extractParameterNamesFromTask(task) {
|
|
3659
|
-
const { title, description,
|
|
3736
|
+
const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
|
|
3660
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
|
+
}
|
|
3661
3748
|
for (const parameterName of [
|
|
3662
3749
|
...extractParameterNames(title),
|
|
3663
3750
|
...extractParameterNames(description || ''),
|
|
3664
|
-
...
|
|
3751
|
+
...contentParameters,
|
|
3665
3752
|
...extractParameterNames(preparedContent || ''),
|
|
3666
3753
|
]) {
|
|
3667
3754
|
parameterNames.add(parameterName);
|
|
3668
3755
|
}
|
|
3669
|
-
/*/
|
|
3670
|
-
// TODO: [🙊] Fix `extractVariablesFromScript` or delete
|
|
3671
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
3672
|
-
for (const parameterName of extractVariablesFromScript(content)) {
|
|
3673
|
-
parameterNames.add(parameterName);
|
|
3674
|
-
}
|
|
3675
|
-
}
|
|
3676
|
-
/**/
|
|
3677
3756
|
for (const jokerName of jokerParameterNames || []) {
|
|
3678
3757
|
parameterNames.add(jokerName);
|
|
3679
3758
|
}
|