@promptbook/remote-client 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 +79 -126
- 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 +79 -126
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/remote-client",
|
|
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-client.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-js": "4.2.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* @generated
|
|
24
24
|
* @see https://github.com/webgptorg/promptbook
|
|
25
25
|
*/
|
|
26
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.86.
|
|
26
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.31';
|
|
27
27
|
/**
|
|
28
28
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
29
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -294,6 +294,13 @@
|
|
|
294
294
|
* @public exported from `@promptbook/core`
|
|
295
295
|
*/
|
|
296
296
|
const DEFAULT_BOOK_OUTPUT_PARAMETER_NAME = 'result';
|
|
297
|
+
// <- TODO: [🧠] Better system for generator warnings - not always "code" and "by `@promptbook/cli`"
|
|
298
|
+
/**
|
|
299
|
+
* The maximum number of iterations for a loops
|
|
300
|
+
*
|
|
301
|
+
* @private within the repository - too low-level in comparison with other `MAX_...`
|
|
302
|
+
*/
|
|
303
|
+
const LOOP_LIMIT = 1000;
|
|
297
304
|
/**
|
|
298
305
|
* Timeout for the connections in milliseconds
|
|
299
306
|
*
|
|
@@ -4735,136 +4742,60 @@
|
|
|
4735
4742
|
}
|
|
4736
4743
|
|
|
4737
4744
|
/**
|
|
4738
|
-
* Parses the
|
|
4745
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4739
4746
|
*
|
|
4740
|
-
* @param
|
|
4741
|
-
* @returns the list of
|
|
4742
|
-
* @public exported from `@promptbook/utils`
|
|
4743
|
-
*/
|
|
4744
|
-
function extractParameterNames(template) {
|
|
4745
|
-
const matches = template.matchAll(/{\w+}/g);
|
|
4746
|
-
const parameterNames = new Set();
|
|
4747
|
-
for (const match of matches) {
|
|
4748
|
-
const parameterName = match[0].slice(1, -1);
|
|
4749
|
-
parameterNames.add(parameterName);
|
|
4750
|
-
}
|
|
4751
|
-
return parameterNames;
|
|
4752
|
-
}
|
|
4753
|
-
|
|
4754
|
-
/**
|
|
4755
|
-
* Extract all used variable names from ginen JavaScript/TypeScript script
|
|
4756
|
-
*
|
|
4757
|
-
* @param script JavaScript/TypeScript script
|
|
4758
|
-
* @returns Set of variable names
|
|
4747
|
+
* @param script from which to extract the variables
|
|
4748
|
+
* @returns the list of variable names
|
|
4759
4749
|
* @throws {ParseError} if the script is invalid
|
|
4760
|
-
* @public exported from `@promptbook/
|
|
4750
|
+
* @public exported from `@promptbook/execute-javascript`
|
|
4761
4751
|
*/
|
|
4762
|
-
function
|
|
4763
|
-
if (script.trim() === '') {
|
|
4764
|
-
return new Set();
|
|
4765
|
-
}
|
|
4752
|
+
function extractVariablesFromJavascript(script) {
|
|
4766
4753
|
const variables = new Set();
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
// Keywords
|
|
4770
|
-
'break',
|
|
4771
|
-
'case',
|
|
4772
|
-
'catch',
|
|
4773
|
-
'class',
|
|
4774
|
-
'const',
|
|
4775
|
-
'continue',
|
|
4776
|
-
'debugger',
|
|
4777
|
-
'default',
|
|
4778
|
-
'delete',
|
|
4779
|
-
'do',
|
|
4780
|
-
'else',
|
|
4781
|
-
'export',
|
|
4782
|
-
'extends',
|
|
4783
|
-
'false',
|
|
4784
|
-
'finally',
|
|
4785
|
-
'for',
|
|
4786
|
-
'function',
|
|
4787
|
-
'if',
|
|
4788
|
-
'import',
|
|
4789
|
-
'in',
|
|
4790
|
-
'instanceof',
|
|
4791
|
-
'let',
|
|
4792
|
-
'new',
|
|
4793
|
-
'null',
|
|
4794
|
-
'return',
|
|
4795
|
-
'super',
|
|
4796
|
-
'switch',
|
|
4797
|
-
'this',
|
|
4798
|
-
'throw',
|
|
4799
|
-
'true',
|
|
4800
|
-
'try',
|
|
4801
|
-
'typeof',
|
|
4802
|
-
'var',
|
|
4803
|
-
'void',
|
|
4804
|
-
'while',
|
|
4805
|
-
'with',
|
|
4806
|
-
'yield',
|
|
4807
|
-
// Common globals
|
|
4808
|
-
'console',
|
|
4809
|
-
'JSON',
|
|
4810
|
-
'Error',
|
|
4811
|
-
// Typescript types
|
|
4812
|
-
'string',
|
|
4813
|
-
'number',
|
|
4814
|
-
'boolean',
|
|
4815
|
-
'object',
|
|
4816
|
-
'symbol',
|
|
4817
|
-
// Common methods on built-in objects
|
|
4818
|
-
'test',
|
|
4819
|
-
'match',
|
|
4820
|
-
'exec',
|
|
4821
|
-
'replace',
|
|
4822
|
-
'search',
|
|
4823
|
-
'split',
|
|
4824
|
-
]);
|
|
4754
|
+
const originalScript = script;
|
|
4755
|
+
script = `(()=>{${script}})()`;
|
|
4825
4756
|
try {
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
while ((match = templateRegex.exec(script)) !== null) {
|
|
4830
|
-
const varName = match[1];
|
|
4831
|
-
if (!exclude.has(varName)) {
|
|
4832
|
-
variables.add(varName);
|
|
4757
|
+
for (let i = 0; i < LOOP_LIMIT; i++)
|
|
4758
|
+
try {
|
|
4759
|
+
eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
|
|
4833
4760
|
}
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4761
|
+
catch (error) {
|
|
4762
|
+
if (!(error instanceof ReferenceError)) {
|
|
4763
|
+
throw error;
|
|
4764
|
+
}
|
|
4765
|
+
/*
|
|
4766
|
+
Note: Parsing the error
|
|
4767
|
+
🌟 Most devices:
|
|
4768
|
+
[PipelineUrlError: thing is not defined]
|
|
4769
|
+
|
|
4770
|
+
🍏 iPhone`s Safari:
|
|
4771
|
+
[PipelineUrlError: Can't find variable: thing]
|
|
4772
|
+
*/
|
|
4773
|
+
let variableName = undefined;
|
|
4774
|
+
if (error.message.startsWith(`Can't`)) {
|
|
4775
|
+
// 🍏 Case
|
|
4776
|
+
variableName = error.message.split(' ').pop();
|
|
4777
|
+
}
|
|
4778
|
+
else {
|
|
4779
|
+
// 🌟 Case
|
|
4780
|
+
variableName = error.message.split(' ').shift();
|
|
4781
|
+
}
|
|
4782
|
+
if (variableName === undefined) {
|
|
4783
|
+
throw error;
|
|
4784
|
+
}
|
|
4785
|
+
if (script.includes(variableName + '(')) {
|
|
4786
|
+
script = `const ${variableName} = ()=>'';` + script;
|
|
4787
|
+
}
|
|
4788
|
+
else {
|
|
4789
|
+
variables.add(variableName);
|
|
4790
|
+
script = `const ${variableName} = '';` + script;
|
|
4791
|
+
}
|
|
4860
4792
|
}
|
|
4861
|
-
}
|
|
4862
4793
|
}
|
|
4863
4794
|
catch (error) {
|
|
4864
4795
|
if (!(error instanceof Error)) {
|
|
4865
4796
|
throw error;
|
|
4866
4797
|
}
|
|
4867
|
-
throw new ParseError(
|
|
4798
|
+
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
4868
4799
|
Can not extract variables from the script
|
|
4869
4800
|
${block(error.stack || error.message)}
|
|
4870
4801
|
|
|
@@ -4877,7 +4808,7 @@
|
|
|
4877
4808
|
The script:
|
|
4878
4809
|
|
|
4879
4810
|
\`\`\`javascript
|
|
4880
|
-
${block(
|
|
4811
|
+
${block(originalScript)}
|
|
4881
4812
|
\`\`\`
|
|
4882
4813
|
`));
|
|
4883
4814
|
}
|
|
@@ -4887,6 +4818,23 @@
|
|
|
4887
4818
|
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
4888
4819
|
*/
|
|
4889
4820
|
|
|
4821
|
+
/**
|
|
4822
|
+
* Parses the task and returns the list of all parameter names
|
|
4823
|
+
*
|
|
4824
|
+
* @param template the string template with parameters in {curly} braces
|
|
4825
|
+
* @returns the list of parameter names
|
|
4826
|
+
* @public exported from `@promptbook/utils`
|
|
4827
|
+
*/
|
|
4828
|
+
function extractParameterNames(template) {
|
|
4829
|
+
const matches = template.matchAll(/{\w+}/g);
|
|
4830
|
+
const parameterNames = new Set();
|
|
4831
|
+
for (const match of matches) {
|
|
4832
|
+
const parameterName = match[0].slice(1, -1);
|
|
4833
|
+
parameterNames.add(parameterName);
|
|
4834
|
+
}
|
|
4835
|
+
return parameterNames;
|
|
4836
|
+
}
|
|
4837
|
+
|
|
4890
4838
|
/**
|
|
4891
4839
|
* Parses the task and returns the set of all used parameters
|
|
4892
4840
|
*
|
|
@@ -4898,19 +4846,24 @@
|
|
|
4898
4846
|
function extractParameterNamesFromTask(task) {
|
|
4899
4847
|
const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
|
|
4900
4848
|
const parameterNames = new Set();
|
|
4849
|
+
let contentParameters;
|
|
4850
|
+
if (taskType !== 'SCRIPT_TASK') {
|
|
4851
|
+
contentParameters = extractParameterNames(content);
|
|
4852
|
+
}
|
|
4853
|
+
else {
|
|
4854
|
+
// TODO: What if script is not javascript?
|
|
4855
|
+
// const { contentLanguage } = task;
|
|
4856
|
+
// if (contentLanguage !== 'javascript') {
|
|
4857
|
+
contentParameters = extractVariablesFromJavascript(content);
|
|
4858
|
+
}
|
|
4901
4859
|
for (const parameterName of [
|
|
4902
4860
|
...extractParameterNames(title),
|
|
4903
4861
|
...extractParameterNames(description || ''),
|
|
4904
|
-
...
|
|
4862
|
+
...contentParameters,
|
|
4905
4863
|
...extractParameterNames(preparedContent || ''),
|
|
4906
4864
|
]) {
|
|
4907
4865
|
parameterNames.add(parameterName);
|
|
4908
4866
|
}
|
|
4909
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
4910
|
-
for (const parameterName of extractVariablesFromScript(content)) {
|
|
4911
|
-
parameterNames.add(parameterName);
|
|
4912
|
-
}
|
|
4913
|
-
}
|
|
4914
4867
|
for (const jokerName of jokerParameterNames || []) {
|
|
4915
4868
|
parameterNames.add(jokerName);
|
|
4916
4869
|
}
|