@promptbook/markitdown 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
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.86.
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.31';
|
|
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
|
|
@@ -3635,6 +3635,83 @@ function valueToString(value) {
|
|
|
3635
3635
|
}
|
|
3636
3636
|
}
|
|
3637
3637
|
|
|
3638
|
+
/**
|
|
3639
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
3640
|
+
*
|
|
3641
|
+
* @param script from which to extract the variables
|
|
3642
|
+
* @returns the list of variable names
|
|
3643
|
+
* @throws {ParseError} if the script is invalid
|
|
3644
|
+
* @public exported from `@promptbook/execute-javascript`
|
|
3645
|
+
*/
|
|
3646
|
+
function extractVariablesFromJavascript(script) {
|
|
3647
|
+
const variables = new Set();
|
|
3648
|
+
const originalScript = script;
|
|
3649
|
+
script = `(()=>{${script}})()`;
|
|
3650
|
+
try {
|
|
3651
|
+
for (let i = 0; i < LOOP_LIMIT; i++)
|
|
3652
|
+
try {
|
|
3653
|
+
eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
|
|
3654
|
+
}
|
|
3655
|
+
catch (error) {
|
|
3656
|
+
if (!(error instanceof ReferenceError)) {
|
|
3657
|
+
throw error;
|
|
3658
|
+
}
|
|
3659
|
+
/*
|
|
3660
|
+
Note: Parsing the error
|
|
3661
|
+
🌟 Most devices:
|
|
3662
|
+
[PipelineUrlError: thing is not defined]
|
|
3663
|
+
|
|
3664
|
+
🍏 iPhone`s Safari:
|
|
3665
|
+
[PipelineUrlError: Can't find variable: thing]
|
|
3666
|
+
*/
|
|
3667
|
+
let variableName = undefined;
|
|
3668
|
+
if (error.message.startsWith(`Can't`)) {
|
|
3669
|
+
// 🍏 Case
|
|
3670
|
+
variableName = error.message.split(' ').pop();
|
|
3671
|
+
}
|
|
3672
|
+
else {
|
|
3673
|
+
// 🌟 Case
|
|
3674
|
+
variableName = error.message.split(' ').shift();
|
|
3675
|
+
}
|
|
3676
|
+
if (variableName === undefined) {
|
|
3677
|
+
throw error;
|
|
3678
|
+
}
|
|
3679
|
+
if (script.includes(variableName + '(')) {
|
|
3680
|
+
script = `const ${variableName} = ()=>'';` + script;
|
|
3681
|
+
}
|
|
3682
|
+
else {
|
|
3683
|
+
variables.add(variableName);
|
|
3684
|
+
script = `const ${variableName} = '';` + script;
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
catch (error) {
|
|
3689
|
+
if (!(error instanceof Error)) {
|
|
3690
|
+
throw error;
|
|
3691
|
+
}
|
|
3692
|
+
throw new ParseError(spaceTrim$1((block) => `
|
|
3693
|
+
Can not extract variables from the script
|
|
3694
|
+
${block(error.stack || error.message)}
|
|
3695
|
+
|
|
3696
|
+
Found variables:
|
|
3697
|
+
${Array.from(variables)
|
|
3698
|
+
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
3699
|
+
.join('\n')}
|
|
3700
|
+
|
|
3701
|
+
|
|
3702
|
+
The script:
|
|
3703
|
+
|
|
3704
|
+
\`\`\`javascript
|
|
3705
|
+
${block(originalScript)}
|
|
3706
|
+
\`\`\`
|
|
3707
|
+
`));
|
|
3708
|
+
}
|
|
3709
|
+
return variables;
|
|
3710
|
+
}
|
|
3711
|
+
/**
|
|
3712
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
3713
|
+
*/
|
|
3714
|
+
|
|
3638
3715
|
/**
|
|
3639
3716
|
* Parses the task and returns the set of all used parameters
|
|
3640
3717
|
*
|
|
@@ -3644,24 +3721,26 @@ function valueToString(value) {
|
|
|
3644
3721
|
* @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
|
|
3645
3722
|
*/
|
|
3646
3723
|
function extractParameterNamesFromTask(task) {
|
|
3647
|
-
const { title, description,
|
|
3724
|
+
const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
|
|
3648
3725
|
const parameterNames = new Set();
|
|
3726
|
+
let contentParameters;
|
|
3727
|
+
if (taskType !== 'SCRIPT_TASK') {
|
|
3728
|
+
contentParameters = extractParameterNames(content);
|
|
3729
|
+
}
|
|
3730
|
+
else {
|
|
3731
|
+
// TODO: What if script is not javascript?
|
|
3732
|
+
// const { contentLanguage } = task;
|
|
3733
|
+
// if (contentLanguage !== 'javascript') {
|
|
3734
|
+
contentParameters = extractVariablesFromJavascript(content);
|
|
3735
|
+
}
|
|
3649
3736
|
for (const parameterName of [
|
|
3650
3737
|
...extractParameterNames(title),
|
|
3651
3738
|
...extractParameterNames(description || ''),
|
|
3652
|
-
...
|
|
3739
|
+
...contentParameters,
|
|
3653
3740
|
...extractParameterNames(preparedContent || ''),
|
|
3654
3741
|
]) {
|
|
3655
3742
|
parameterNames.add(parameterName);
|
|
3656
3743
|
}
|
|
3657
|
-
/*/
|
|
3658
|
-
// TODO: [🙊] Fix `extractVariablesFromScript` or delete
|
|
3659
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
3660
|
-
for (const parameterName of extractVariablesFromScript(content)) {
|
|
3661
|
-
parameterNames.add(parameterName);
|
|
3662
|
-
}
|
|
3663
|
-
}
|
|
3664
|
-
/**/
|
|
3665
3744
|
for (const jokerName of jokerParameterNames || []) {
|
|
3666
3745
|
parameterNames.add(jokerName);
|
|
3667
3746
|
}
|