@promptbook/remote-client 0.86.30 → 0.88.0-1
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/README.md +5 -3
- package/esm/index.es.js +97 -11
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/{execute-javascript.index.d.ts → javascript.index.d.ts} +2 -0
- package/esm/typings/src/_packages/node.index.d.ts +2 -0
- package/esm/typings/src/scrapers/_common/register/$provideScriptingForNode.d.ts +11 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +1 -1
- 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 +97 -11
- package/umd/index.umd.js.map +1 -1
|
@@ -6,7 +6,7 @@ import type { JavascriptExecutionToolsOptions } from './JavascriptExecutionTools
|
|
|
6
6
|
* Warning: It is used for testing and mocking
|
|
7
7
|
* **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
|
|
8
8
|
*
|
|
9
|
-
* @public exported from `@promptbook/
|
|
9
|
+
* @public exported from `@promptbook/javascript`
|
|
10
10
|
*/
|
|
11
11
|
export declare class JavascriptEvalExecutionTools implements ScriptExecutionTools {
|
|
12
12
|
protected readonly options: JavascriptExecutionToolsOptions;
|
|
@@ -3,6 +3,6 @@ import { JavascriptEvalExecutionTools } from './JavascriptEvalExecutionTools';
|
|
|
3
3
|
* Placeholder for better implementation of JavascriptExecutionTools - some propper sandboxing
|
|
4
4
|
*
|
|
5
5
|
* @alias JavascriptExecutionTools
|
|
6
|
-
* @public exported from `@promptbook/
|
|
6
|
+
* @public exported from `@promptbook/javascript`
|
|
7
7
|
*/
|
|
8
8
|
export declare const JavascriptExecutionTools: typeof JavascriptEvalExecutionTools;
|
|
@@ -20,7 +20,7 @@ import { unwrapResult } from '../../utils/unwrapResult';
|
|
|
20
20
|
/**
|
|
21
21
|
* @@@
|
|
22
22
|
*
|
|
23
|
-
* @public exported from `@promptbook/
|
|
23
|
+
* @public exported from `@promptbook/javascript`
|
|
24
24
|
*/
|
|
25
25
|
export declare const POSTPROCESSING_FUNCTIONS: {
|
|
26
26
|
spaceTrim: typeof spaceTrim;
|
|
@@ -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/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/remote-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.88.0-1",
|
|
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.
|
|
50
|
+
"@promptbook/core": "0.88.0-1"
|
|
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.
|
|
26
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-1';
|
|
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
|
*
|
|
@@ -4734,6 +4741,83 @@
|
|
|
4734
4741
|
return value;
|
|
4735
4742
|
}
|
|
4736
4743
|
|
|
4744
|
+
/**
|
|
4745
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
4746
|
+
*
|
|
4747
|
+
* @param script from which to extract the variables
|
|
4748
|
+
* @returns the list of variable names
|
|
4749
|
+
* @throws {ParseError} if the script is invalid
|
|
4750
|
+
* @public exported from `@promptbook/javascript`
|
|
4751
|
+
*/
|
|
4752
|
+
function extractVariablesFromJavascript(script) {
|
|
4753
|
+
const variables = new Set();
|
|
4754
|
+
const originalScript = script;
|
|
4755
|
+
script = `(()=>{${script}})()`;
|
|
4756
|
+
try {
|
|
4757
|
+
for (let i = 0; i < LOOP_LIMIT; i++)
|
|
4758
|
+
try {
|
|
4759
|
+
eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
|
|
4760
|
+
}
|
|
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
|
+
}
|
|
4792
|
+
}
|
|
4793
|
+
}
|
|
4794
|
+
catch (error) {
|
|
4795
|
+
if (!(error instanceof Error)) {
|
|
4796
|
+
throw error;
|
|
4797
|
+
}
|
|
4798
|
+
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
4799
|
+
Can not extract variables from the script
|
|
4800
|
+
${block(error.stack || error.message)}
|
|
4801
|
+
|
|
4802
|
+
Found variables:
|
|
4803
|
+
${Array.from(variables)
|
|
4804
|
+
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
4805
|
+
.join('\n')}
|
|
4806
|
+
|
|
4807
|
+
|
|
4808
|
+
The script:
|
|
4809
|
+
|
|
4810
|
+
\`\`\`javascript
|
|
4811
|
+
${block(originalScript)}
|
|
4812
|
+
\`\`\`
|
|
4813
|
+
`));
|
|
4814
|
+
}
|
|
4815
|
+
return variables;
|
|
4816
|
+
}
|
|
4817
|
+
/**
|
|
4818
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
4819
|
+
*/
|
|
4820
|
+
|
|
4737
4821
|
/**
|
|
4738
4822
|
* Parses the task and returns the list of all parameter names
|
|
4739
4823
|
*
|
|
@@ -4760,24 +4844,26 @@
|
|
|
4760
4844
|
* @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
|
|
4761
4845
|
*/
|
|
4762
4846
|
function extractParameterNamesFromTask(task) {
|
|
4763
|
-
const { title, description,
|
|
4847
|
+
const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
|
|
4764
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
|
+
}
|
|
4765
4859
|
for (const parameterName of [
|
|
4766
4860
|
...extractParameterNames(title),
|
|
4767
4861
|
...extractParameterNames(description || ''),
|
|
4768
|
-
...
|
|
4862
|
+
...contentParameters,
|
|
4769
4863
|
...extractParameterNames(preparedContent || ''),
|
|
4770
4864
|
]) {
|
|
4771
4865
|
parameterNames.add(parameterName);
|
|
4772
4866
|
}
|
|
4773
|
-
/*/
|
|
4774
|
-
// TODO: [🙊] Fix `extractVariablesFromScript` or delete
|
|
4775
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
4776
|
-
for (const parameterName of extractVariablesFromScript(content)) {
|
|
4777
|
-
parameterNames.add(parameterName);
|
|
4778
|
-
}
|
|
4779
|
-
}
|
|
4780
|
-
/**/
|
|
4781
4867
|
for (const jokerName of jokerParameterNames || []) {
|
|
4782
4868
|
parameterNames.add(jokerName);
|
|
4783
4869
|
}
|