@promptbook/remote-client 0.86.22 → 0.86.30
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 +5 -138
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +0 -2
- package/package.json +2 -2
- package/umd/index.umd.js +5 -138
- 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 +0 -1
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +0 -4
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.30';
|
|
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
|
|
@@ -4751,142 +4751,6 @@
|
|
|
4751
4751
|
return parameterNames;
|
|
4752
4752
|
}
|
|
4753
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
|
|
4759
|
-
* @throws {ParseError} if the script is invalid
|
|
4760
|
-
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
4761
|
-
*/
|
|
4762
|
-
function extractVariablesFromScript(script) {
|
|
4763
|
-
if (script.trim() === '') {
|
|
4764
|
-
return new Set();
|
|
4765
|
-
}
|
|
4766
|
-
const variables = new Set();
|
|
4767
|
-
// JS keywords and builtins to exclude
|
|
4768
|
-
const exclude = new Set([
|
|
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
|
-
]);
|
|
4825
|
-
try {
|
|
4826
|
-
// Note: Extract variables from template literals like ${variable}
|
|
4827
|
-
const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
|
|
4828
|
-
let match;
|
|
4829
|
-
while ((match = templateRegex.exec(script)) !== null) {
|
|
4830
|
-
const varName = match[1];
|
|
4831
|
-
if (!exclude.has(varName)) {
|
|
4832
|
-
variables.add(varName);
|
|
4833
|
-
}
|
|
4834
|
-
}
|
|
4835
|
-
// Note: Process the script to handle normal variable usage
|
|
4836
|
-
const processedScript = script
|
|
4837
|
-
.replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
|
|
4838
|
-
.replace(/"(?:\\.|[^"\\])*"/g, '""')
|
|
4839
|
-
.replace(/`(?:\\.|[^`\\])*`/g, '``')
|
|
4840
|
-
.replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
|
|
4841
|
-
// Note: Find identifiers in function arguments
|
|
4842
|
-
const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
|
|
4843
|
-
const funcNames = new Set();
|
|
4844
|
-
while ((match = funcArgRegex.exec(processedScript)) !== null) {
|
|
4845
|
-
funcNames.add(match[1]);
|
|
4846
|
-
}
|
|
4847
|
-
// Find variable declarations to exclude them
|
|
4848
|
-
const declaredVars = new Set();
|
|
4849
|
-
const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
4850
|
-
while ((match = declRegex.exec(processedScript)) !== null) {
|
|
4851
|
-
declaredVars.add(match[2]);
|
|
4852
|
-
}
|
|
4853
|
-
// Note: Find identifiers in the script
|
|
4854
|
-
const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
4855
|
-
while ((match = identifierRegex.exec(processedScript)) !== null) {
|
|
4856
|
-
const name = match[1];
|
|
4857
|
-
// Add if not excluded, not a function name, and not a declared variable
|
|
4858
|
-
if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
|
|
4859
|
-
variables.add(name);
|
|
4860
|
-
}
|
|
4861
|
-
}
|
|
4862
|
-
}
|
|
4863
|
-
catch (error) {
|
|
4864
|
-
if (!(error instanceof Error)) {
|
|
4865
|
-
throw error;
|
|
4866
|
-
}
|
|
4867
|
-
throw new ParseError(spaceTrim__default["default"]((block) => `
|
|
4868
|
-
Can not extract variables from the script
|
|
4869
|
-
${block(error.stack || error.message)}
|
|
4870
|
-
|
|
4871
|
-
Found variables:
|
|
4872
|
-
${Array.from(variables)
|
|
4873
|
-
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
4874
|
-
.join('\n')}
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
The script:
|
|
4878
|
-
|
|
4879
|
-
\`\`\`javascript
|
|
4880
|
-
${block(script)}
|
|
4881
|
-
\`\`\`
|
|
4882
|
-
`));
|
|
4883
|
-
}
|
|
4884
|
-
return variables;
|
|
4885
|
-
}
|
|
4886
|
-
/**
|
|
4887
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
4888
|
-
*/
|
|
4889
|
-
|
|
4890
4754
|
/**
|
|
4891
4755
|
* Parses the task and returns the set of all used parameters
|
|
4892
4756
|
*
|
|
@@ -4896,7 +4760,7 @@
|
|
|
4896
4760
|
* @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
|
|
4897
4761
|
*/
|
|
4898
4762
|
function extractParameterNamesFromTask(task) {
|
|
4899
|
-
const { title, description, taskType
|
|
4763
|
+
const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
|
|
4900
4764
|
const parameterNames = new Set();
|
|
4901
4765
|
for (const parameterName of [
|
|
4902
4766
|
...extractParameterNames(title),
|
|
@@ -4906,11 +4770,14 @@
|
|
|
4906
4770
|
]) {
|
|
4907
4771
|
parameterNames.add(parameterName);
|
|
4908
4772
|
}
|
|
4773
|
+
/*/
|
|
4774
|
+
// TODO: [🙊] Fix `extractVariablesFromScript` or delete
|
|
4909
4775
|
if (taskType === 'SCRIPT_TASK') {
|
|
4910
4776
|
for (const parameterName of extractVariablesFromScript(content)) {
|
|
4911
4777
|
parameterNames.add(parameterName);
|
|
4912
4778
|
}
|
|
4913
4779
|
}
|
|
4780
|
+
/**/
|
|
4914
4781
|
for (const jokerName of jokerParameterNames || []) {
|
|
4915
4782
|
parameterNames.add(jokerName);
|
|
4916
4783
|
}
|