@promptbook/remote-server 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
|
@@ -31,7 +31,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
31
31
|
* @generated
|
|
32
32
|
* @see https://github.com/webgptorg/promptbook
|
|
33
33
|
*/
|
|
34
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.86.
|
|
34
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.30';
|
|
35
35
|
/**
|
|
36
36
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
37
37
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -3966,142 +3966,6 @@ function valueToString(value) {
|
|
|
3966
3966
|
}
|
|
3967
3967
|
}
|
|
3968
3968
|
|
|
3969
|
-
/**
|
|
3970
|
-
* Extract all used variable names from ginen JavaScript/TypeScript script
|
|
3971
|
-
*
|
|
3972
|
-
* @param script JavaScript/TypeScript script
|
|
3973
|
-
* @returns Set of variable names
|
|
3974
|
-
* @throws {ParseError} if the script is invalid
|
|
3975
|
-
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
3976
|
-
*/
|
|
3977
|
-
function extractVariablesFromScript(script) {
|
|
3978
|
-
if (script.trim() === '') {
|
|
3979
|
-
return new Set();
|
|
3980
|
-
}
|
|
3981
|
-
const variables = new Set();
|
|
3982
|
-
// JS keywords and builtins to exclude
|
|
3983
|
-
const exclude = new Set([
|
|
3984
|
-
// Keywords
|
|
3985
|
-
'break',
|
|
3986
|
-
'case',
|
|
3987
|
-
'catch',
|
|
3988
|
-
'class',
|
|
3989
|
-
'const',
|
|
3990
|
-
'continue',
|
|
3991
|
-
'debugger',
|
|
3992
|
-
'default',
|
|
3993
|
-
'delete',
|
|
3994
|
-
'do',
|
|
3995
|
-
'else',
|
|
3996
|
-
'export',
|
|
3997
|
-
'extends',
|
|
3998
|
-
'false',
|
|
3999
|
-
'finally',
|
|
4000
|
-
'for',
|
|
4001
|
-
'function',
|
|
4002
|
-
'if',
|
|
4003
|
-
'import',
|
|
4004
|
-
'in',
|
|
4005
|
-
'instanceof',
|
|
4006
|
-
'let',
|
|
4007
|
-
'new',
|
|
4008
|
-
'null',
|
|
4009
|
-
'return',
|
|
4010
|
-
'super',
|
|
4011
|
-
'switch',
|
|
4012
|
-
'this',
|
|
4013
|
-
'throw',
|
|
4014
|
-
'true',
|
|
4015
|
-
'try',
|
|
4016
|
-
'typeof',
|
|
4017
|
-
'var',
|
|
4018
|
-
'void',
|
|
4019
|
-
'while',
|
|
4020
|
-
'with',
|
|
4021
|
-
'yield',
|
|
4022
|
-
// Common globals
|
|
4023
|
-
'console',
|
|
4024
|
-
'JSON',
|
|
4025
|
-
'Error',
|
|
4026
|
-
// Typescript types
|
|
4027
|
-
'string',
|
|
4028
|
-
'number',
|
|
4029
|
-
'boolean',
|
|
4030
|
-
'object',
|
|
4031
|
-
'symbol',
|
|
4032
|
-
// Common methods on built-in objects
|
|
4033
|
-
'test',
|
|
4034
|
-
'match',
|
|
4035
|
-
'exec',
|
|
4036
|
-
'replace',
|
|
4037
|
-
'search',
|
|
4038
|
-
'split',
|
|
4039
|
-
]);
|
|
4040
|
-
try {
|
|
4041
|
-
// Note: Extract variables from template literals like ${variable}
|
|
4042
|
-
const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
|
|
4043
|
-
let match;
|
|
4044
|
-
while ((match = templateRegex.exec(script)) !== null) {
|
|
4045
|
-
const varName = match[1];
|
|
4046
|
-
if (!exclude.has(varName)) {
|
|
4047
|
-
variables.add(varName);
|
|
4048
|
-
}
|
|
4049
|
-
}
|
|
4050
|
-
// Note: Process the script to handle normal variable usage
|
|
4051
|
-
const processedScript = script
|
|
4052
|
-
.replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
|
|
4053
|
-
.replace(/"(?:\\.|[^"\\])*"/g, '""')
|
|
4054
|
-
.replace(/`(?:\\.|[^`\\])*`/g, '``')
|
|
4055
|
-
.replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
|
|
4056
|
-
// Note: Find identifiers in function arguments
|
|
4057
|
-
const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
|
|
4058
|
-
const funcNames = new Set();
|
|
4059
|
-
while ((match = funcArgRegex.exec(processedScript)) !== null) {
|
|
4060
|
-
funcNames.add(match[1]);
|
|
4061
|
-
}
|
|
4062
|
-
// Find variable declarations to exclude them
|
|
4063
|
-
const declaredVars = new Set();
|
|
4064
|
-
const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
4065
|
-
while ((match = declRegex.exec(processedScript)) !== null) {
|
|
4066
|
-
declaredVars.add(match[2]);
|
|
4067
|
-
}
|
|
4068
|
-
// Note: Find identifiers in the script
|
|
4069
|
-
const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
4070
|
-
while ((match = identifierRegex.exec(processedScript)) !== null) {
|
|
4071
|
-
const name = match[1];
|
|
4072
|
-
// Add if not excluded, not a function name, and not a declared variable
|
|
4073
|
-
if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
|
|
4074
|
-
variables.add(name);
|
|
4075
|
-
}
|
|
4076
|
-
}
|
|
4077
|
-
}
|
|
4078
|
-
catch (error) {
|
|
4079
|
-
if (!(error instanceof Error)) {
|
|
4080
|
-
throw error;
|
|
4081
|
-
}
|
|
4082
|
-
throw new ParseError(spaceTrim$1((block) => `
|
|
4083
|
-
Can not extract variables from the script
|
|
4084
|
-
${block(error.stack || error.message)}
|
|
4085
|
-
|
|
4086
|
-
Found variables:
|
|
4087
|
-
${Array.from(variables)
|
|
4088
|
-
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
4089
|
-
.join('\n')}
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
The script:
|
|
4093
|
-
|
|
4094
|
-
\`\`\`javascript
|
|
4095
|
-
${block(script)}
|
|
4096
|
-
\`\`\`
|
|
4097
|
-
`));
|
|
4098
|
-
}
|
|
4099
|
-
return variables;
|
|
4100
|
-
}
|
|
4101
|
-
/**
|
|
4102
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
4103
|
-
*/
|
|
4104
|
-
|
|
4105
3969
|
/**
|
|
4106
3970
|
* Parses the task and returns the set of all used parameters
|
|
4107
3971
|
*
|
|
@@ -4111,7 +3975,7 @@ function extractVariablesFromScript(script) {
|
|
|
4111
3975
|
* @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
|
|
4112
3976
|
*/
|
|
4113
3977
|
function extractParameterNamesFromTask(task) {
|
|
4114
|
-
const { title, description, taskType
|
|
3978
|
+
const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
|
|
4115
3979
|
const parameterNames = new Set();
|
|
4116
3980
|
for (const parameterName of [
|
|
4117
3981
|
...extractParameterNames(title),
|
|
@@ -4121,11 +3985,14 @@ function extractParameterNamesFromTask(task) {
|
|
|
4121
3985
|
]) {
|
|
4122
3986
|
parameterNames.add(parameterName);
|
|
4123
3987
|
}
|
|
3988
|
+
/*/
|
|
3989
|
+
// TODO: [🙊] Fix `extractVariablesFromScript` or delete
|
|
4124
3990
|
if (taskType === 'SCRIPT_TASK') {
|
|
4125
3991
|
for (const parameterName of extractVariablesFromScript(content)) {
|
|
4126
3992
|
parameterNames.add(parameterName);
|
|
4127
3993
|
}
|
|
4128
3994
|
}
|
|
3995
|
+
/**/
|
|
4129
3996
|
for (const jokerName of jokerParameterNames || []) {
|
|
4130
3997
|
parameterNames.add(jokerName);
|
|
4131
3998
|
}
|