@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/esm/index.es.js
CHANGED
|
@@ -19,7 +19,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
19
19
|
* @generated
|
|
20
20
|
* @see https://github.com/webgptorg/promptbook
|
|
21
21
|
*/
|
|
22
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.86.
|
|
22
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.30';
|
|
23
23
|
/**
|
|
24
24
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
25
25
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -4747,142 +4747,6 @@ function extractParameterNames(template) {
|
|
|
4747
4747
|
return parameterNames;
|
|
4748
4748
|
}
|
|
4749
4749
|
|
|
4750
|
-
/**
|
|
4751
|
-
* Extract all used variable names from ginen JavaScript/TypeScript script
|
|
4752
|
-
*
|
|
4753
|
-
* @param script JavaScript/TypeScript script
|
|
4754
|
-
* @returns Set of variable names
|
|
4755
|
-
* @throws {ParseError} if the script is invalid
|
|
4756
|
-
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
4757
|
-
*/
|
|
4758
|
-
function extractVariablesFromScript(script) {
|
|
4759
|
-
if (script.trim() === '') {
|
|
4760
|
-
return new Set();
|
|
4761
|
-
}
|
|
4762
|
-
const variables = new Set();
|
|
4763
|
-
// JS keywords and builtins to exclude
|
|
4764
|
-
const exclude = new Set([
|
|
4765
|
-
// Keywords
|
|
4766
|
-
'break',
|
|
4767
|
-
'case',
|
|
4768
|
-
'catch',
|
|
4769
|
-
'class',
|
|
4770
|
-
'const',
|
|
4771
|
-
'continue',
|
|
4772
|
-
'debugger',
|
|
4773
|
-
'default',
|
|
4774
|
-
'delete',
|
|
4775
|
-
'do',
|
|
4776
|
-
'else',
|
|
4777
|
-
'export',
|
|
4778
|
-
'extends',
|
|
4779
|
-
'false',
|
|
4780
|
-
'finally',
|
|
4781
|
-
'for',
|
|
4782
|
-
'function',
|
|
4783
|
-
'if',
|
|
4784
|
-
'import',
|
|
4785
|
-
'in',
|
|
4786
|
-
'instanceof',
|
|
4787
|
-
'let',
|
|
4788
|
-
'new',
|
|
4789
|
-
'null',
|
|
4790
|
-
'return',
|
|
4791
|
-
'super',
|
|
4792
|
-
'switch',
|
|
4793
|
-
'this',
|
|
4794
|
-
'throw',
|
|
4795
|
-
'true',
|
|
4796
|
-
'try',
|
|
4797
|
-
'typeof',
|
|
4798
|
-
'var',
|
|
4799
|
-
'void',
|
|
4800
|
-
'while',
|
|
4801
|
-
'with',
|
|
4802
|
-
'yield',
|
|
4803
|
-
// Common globals
|
|
4804
|
-
'console',
|
|
4805
|
-
'JSON',
|
|
4806
|
-
'Error',
|
|
4807
|
-
// Typescript types
|
|
4808
|
-
'string',
|
|
4809
|
-
'number',
|
|
4810
|
-
'boolean',
|
|
4811
|
-
'object',
|
|
4812
|
-
'symbol',
|
|
4813
|
-
// Common methods on built-in objects
|
|
4814
|
-
'test',
|
|
4815
|
-
'match',
|
|
4816
|
-
'exec',
|
|
4817
|
-
'replace',
|
|
4818
|
-
'search',
|
|
4819
|
-
'split',
|
|
4820
|
-
]);
|
|
4821
|
-
try {
|
|
4822
|
-
// Note: Extract variables from template literals like ${variable}
|
|
4823
|
-
const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
|
|
4824
|
-
let match;
|
|
4825
|
-
while ((match = templateRegex.exec(script)) !== null) {
|
|
4826
|
-
const varName = match[1];
|
|
4827
|
-
if (!exclude.has(varName)) {
|
|
4828
|
-
variables.add(varName);
|
|
4829
|
-
}
|
|
4830
|
-
}
|
|
4831
|
-
// Note: Process the script to handle normal variable usage
|
|
4832
|
-
const processedScript = script
|
|
4833
|
-
.replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
|
|
4834
|
-
.replace(/"(?:\\.|[^"\\])*"/g, '""')
|
|
4835
|
-
.replace(/`(?:\\.|[^`\\])*`/g, '``')
|
|
4836
|
-
.replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
|
|
4837
|
-
// Note: Find identifiers in function arguments
|
|
4838
|
-
const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
|
|
4839
|
-
const funcNames = new Set();
|
|
4840
|
-
while ((match = funcArgRegex.exec(processedScript)) !== null) {
|
|
4841
|
-
funcNames.add(match[1]);
|
|
4842
|
-
}
|
|
4843
|
-
// Find variable declarations to exclude them
|
|
4844
|
-
const declaredVars = new Set();
|
|
4845
|
-
const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
4846
|
-
while ((match = declRegex.exec(processedScript)) !== null) {
|
|
4847
|
-
declaredVars.add(match[2]);
|
|
4848
|
-
}
|
|
4849
|
-
// Note: Find identifiers in the script
|
|
4850
|
-
const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
4851
|
-
while ((match = identifierRegex.exec(processedScript)) !== null) {
|
|
4852
|
-
const name = match[1];
|
|
4853
|
-
// Add if not excluded, not a function name, and not a declared variable
|
|
4854
|
-
if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
|
|
4855
|
-
variables.add(name);
|
|
4856
|
-
}
|
|
4857
|
-
}
|
|
4858
|
-
}
|
|
4859
|
-
catch (error) {
|
|
4860
|
-
if (!(error instanceof Error)) {
|
|
4861
|
-
throw error;
|
|
4862
|
-
}
|
|
4863
|
-
throw new ParseError(spaceTrim$1((block) => `
|
|
4864
|
-
Can not extract variables from the script
|
|
4865
|
-
${block(error.stack || error.message)}
|
|
4866
|
-
|
|
4867
|
-
Found variables:
|
|
4868
|
-
${Array.from(variables)
|
|
4869
|
-
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
4870
|
-
.join('\n')}
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
The script:
|
|
4874
|
-
|
|
4875
|
-
\`\`\`javascript
|
|
4876
|
-
${block(script)}
|
|
4877
|
-
\`\`\`
|
|
4878
|
-
`));
|
|
4879
|
-
}
|
|
4880
|
-
return variables;
|
|
4881
|
-
}
|
|
4882
|
-
/**
|
|
4883
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
4884
|
-
*/
|
|
4885
|
-
|
|
4886
4750
|
/**
|
|
4887
4751
|
* Parses the task and returns the set of all used parameters
|
|
4888
4752
|
*
|
|
@@ -4892,7 +4756,7 @@ function extractVariablesFromScript(script) {
|
|
|
4892
4756
|
* @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
|
|
4893
4757
|
*/
|
|
4894
4758
|
function extractParameterNamesFromTask(task) {
|
|
4895
|
-
const { title, description, taskType
|
|
4759
|
+
const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
|
|
4896
4760
|
const parameterNames = new Set();
|
|
4897
4761
|
for (const parameterName of [
|
|
4898
4762
|
...extractParameterNames(title),
|
|
@@ -4902,11 +4766,14 @@ function extractParameterNamesFromTask(task) {
|
|
|
4902
4766
|
]) {
|
|
4903
4767
|
parameterNames.add(parameterName);
|
|
4904
4768
|
}
|
|
4769
|
+
/*/
|
|
4770
|
+
// TODO: [🙊] Fix `extractVariablesFromScript` or delete
|
|
4905
4771
|
if (taskType === 'SCRIPT_TASK') {
|
|
4906
4772
|
for (const parameterName of extractVariablesFromScript(content)) {
|
|
4907
4773
|
parameterNames.add(parameterName);
|
|
4908
4774
|
}
|
|
4909
4775
|
}
|
|
4776
|
+
/**/
|
|
4910
4777
|
for (const jokerName of jokerParameterNames || []) {
|
|
4911
4778
|
parameterNames.add(jokerName);
|
|
4912
4779
|
}
|