@promptbook/remote-server 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/remote-server",
|
|
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/remote-server.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.86.
|
|
50
|
+
"@promptbook/core": "0.86.31"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
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.31';
|
|
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
|
|
@@ -3964,119 +3964,60 @@
|
|
|
3964
3964
|
}
|
|
3965
3965
|
|
|
3966
3966
|
/**
|
|
3967
|
-
*
|
|
3967
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
3968
3968
|
*
|
|
3969
|
-
* @param script
|
|
3970
|
-
* @returns
|
|
3969
|
+
* @param script from which to extract the variables
|
|
3970
|
+
* @returns the list of variable names
|
|
3971
3971
|
* @throws {ParseError} if the script is invalid
|
|
3972
|
-
* @public exported from `@promptbook/
|
|
3972
|
+
* @public exported from `@promptbook/execute-javascript`
|
|
3973
3973
|
*/
|
|
3974
|
-
function
|
|
3975
|
-
if (script.trim() === '') {
|
|
3976
|
-
return new Set();
|
|
3977
|
-
}
|
|
3974
|
+
function extractVariablesFromJavascript(script) {
|
|
3978
3975
|
const variables = new Set();
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
// Keywords
|
|
3982
|
-
'break',
|
|
3983
|
-
'case',
|
|
3984
|
-
'catch',
|
|
3985
|
-
'class',
|
|
3986
|
-
'const',
|
|
3987
|
-
'continue',
|
|
3988
|
-
'debugger',
|
|
3989
|
-
'default',
|
|
3990
|
-
'delete',
|
|
3991
|
-
'do',
|
|
3992
|
-
'else',
|
|
3993
|
-
'export',
|
|
3994
|
-
'extends',
|
|
3995
|
-
'false',
|
|
3996
|
-
'finally',
|
|
3997
|
-
'for',
|
|
3998
|
-
'function',
|
|
3999
|
-
'if',
|
|
4000
|
-
'import',
|
|
4001
|
-
'in',
|
|
4002
|
-
'instanceof',
|
|
4003
|
-
'let',
|
|
4004
|
-
'new',
|
|
4005
|
-
'null',
|
|
4006
|
-
'return',
|
|
4007
|
-
'super',
|
|
4008
|
-
'switch',
|
|
4009
|
-
'this',
|
|
4010
|
-
'throw',
|
|
4011
|
-
'true',
|
|
4012
|
-
'try',
|
|
4013
|
-
'typeof',
|
|
4014
|
-
'var',
|
|
4015
|
-
'void',
|
|
4016
|
-
'while',
|
|
4017
|
-
'with',
|
|
4018
|
-
'yield',
|
|
4019
|
-
// Common globals
|
|
4020
|
-
'console',
|
|
4021
|
-
'JSON',
|
|
4022
|
-
'Error',
|
|
4023
|
-
// Typescript types
|
|
4024
|
-
'string',
|
|
4025
|
-
'number',
|
|
4026
|
-
'boolean',
|
|
4027
|
-
'object',
|
|
4028
|
-
'symbol',
|
|
4029
|
-
// Common methods on built-in objects
|
|
4030
|
-
'test',
|
|
4031
|
-
'match',
|
|
4032
|
-
'exec',
|
|
4033
|
-
'replace',
|
|
4034
|
-
'search',
|
|
4035
|
-
'split',
|
|
4036
|
-
]);
|
|
3976
|
+
const originalScript = script;
|
|
3977
|
+
script = `(()=>{${script}})()`;
|
|
4037
3978
|
try {
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
while ((match = templateRegex.exec(script)) !== null) {
|
|
4042
|
-
const varName = match[1];
|
|
4043
|
-
if (!exclude.has(varName)) {
|
|
4044
|
-
variables.add(varName);
|
|
3979
|
+
for (let i = 0; i < LOOP_LIMIT; i++)
|
|
3980
|
+
try {
|
|
3981
|
+
eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
|
|
4045
3982
|
}
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
3983
|
+
catch (error) {
|
|
3984
|
+
if (!(error instanceof ReferenceError)) {
|
|
3985
|
+
throw error;
|
|
3986
|
+
}
|
|
3987
|
+
/*
|
|
3988
|
+
Note: Parsing the error
|
|
3989
|
+
🌟 Most devices:
|
|
3990
|
+
[PipelineUrlError: thing is not defined]
|
|
3991
|
+
|
|
3992
|
+
🍏 iPhone`s Safari:
|
|
3993
|
+
[PipelineUrlError: Can't find variable: thing]
|
|
3994
|
+
*/
|
|
3995
|
+
let variableName = undefined;
|
|
3996
|
+
if (error.message.startsWith(`Can't`)) {
|
|
3997
|
+
// 🍏 Case
|
|
3998
|
+
variableName = error.message.split(' ').pop();
|
|
3999
|
+
}
|
|
4000
|
+
else {
|
|
4001
|
+
// 🌟 Case
|
|
4002
|
+
variableName = error.message.split(' ').shift();
|
|
4003
|
+
}
|
|
4004
|
+
if (variableName === undefined) {
|
|
4005
|
+
throw error;
|
|
4006
|
+
}
|
|
4007
|
+
if (script.includes(variableName + '(')) {
|
|
4008
|
+
script = `const ${variableName} = ()=>'';` + script;
|
|
4009
|
+
}
|
|
4010
|
+
else {
|
|
4011
|
+
variables.add(variableName);
|
|
4012
|
+
script = `const ${variableName} = '';` + script;
|
|
4013
|
+
}
|
|
4072
4014
|
}
|
|
4073
|
-
}
|
|
4074
4015
|
}
|
|
4075
4016
|
catch (error) {
|
|
4076
4017
|
if (!(error instanceof Error)) {
|
|
4077
4018
|
throw error;
|
|
4078
4019
|
}
|
|
4079
|
-
throw new ParseError(
|
|
4020
|
+
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
4080
4021
|
Can not extract variables from the script
|
|
4081
4022
|
${block(error.stack || error.message)}
|
|
4082
4023
|
|
|
@@ -4089,7 +4030,7 @@
|
|
|
4089
4030
|
The script:
|
|
4090
4031
|
|
|
4091
4032
|
\`\`\`javascript
|
|
4092
|
-
${block(
|
|
4033
|
+
${block(originalScript)}
|
|
4093
4034
|
\`\`\`
|
|
4094
4035
|
`));
|
|
4095
4036
|
}
|
|
@@ -4110,19 +4051,24 @@
|
|
|
4110
4051
|
function extractParameterNamesFromTask(task) {
|
|
4111
4052
|
const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
|
|
4112
4053
|
const parameterNames = new Set();
|
|
4054
|
+
let contentParameters;
|
|
4055
|
+
if (taskType !== 'SCRIPT_TASK') {
|
|
4056
|
+
contentParameters = extractParameterNames(content);
|
|
4057
|
+
}
|
|
4058
|
+
else {
|
|
4059
|
+
// TODO: What if script is not javascript?
|
|
4060
|
+
// const { contentLanguage } = task;
|
|
4061
|
+
// if (contentLanguage !== 'javascript') {
|
|
4062
|
+
contentParameters = extractVariablesFromJavascript(content);
|
|
4063
|
+
}
|
|
4113
4064
|
for (const parameterName of [
|
|
4114
4065
|
...extractParameterNames(title),
|
|
4115
4066
|
...extractParameterNames(description || ''),
|
|
4116
|
-
...
|
|
4067
|
+
...contentParameters,
|
|
4117
4068
|
...extractParameterNames(preparedContent || ''),
|
|
4118
4069
|
]) {
|
|
4119
4070
|
parameterNames.add(parameterName);
|
|
4120
4071
|
}
|
|
4121
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
4122
|
-
for (const parameterName of extractVariablesFromScript(content)) {
|
|
4123
|
-
parameterNames.add(parameterName);
|
|
4124
|
-
}
|
|
4125
|
-
}
|
|
4126
4072
|
for (const jokerName of jokerParameterNames || []) {
|
|
4127
4073
|
parameterNames.add(jokerName);
|
|
4128
4074
|
}
|