@promptbook/node 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 CHANGED
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.86.22';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.86.30';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2116,142 +2116,6 @@ function addUsage(...usageItems) {
2116
2116
  }, deepClone(ZERO_USAGE));
2117
2117
  }
2118
2118
 
2119
- /**
2120
- * Extract all used variable names from ginen JavaScript/TypeScript script
2121
- *
2122
- * @param script JavaScript/TypeScript script
2123
- * @returns Set of variable names
2124
- * @throws {ParseError} if the script is invalid
2125
- * @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
2126
- */
2127
- function extractVariablesFromScript(script) {
2128
- if (script.trim() === '') {
2129
- return new Set();
2130
- }
2131
- const variables = new Set();
2132
- // JS keywords and builtins to exclude
2133
- const exclude = new Set([
2134
- // Keywords
2135
- 'break',
2136
- 'case',
2137
- 'catch',
2138
- 'class',
2139
- 'const',
2140
- 'continue',
2141
- 'debugger',
2142
- 'default',
2143
- 'delete',
2144
- 'do',
2145
- 'else',
2146
- 'export',
2147
- 'extends',
2148
- 'false',
2149
- 'finally',
2150
- 'for',
2151
- 'function',
2152
- 'if',
2153
- 'import',
2154
- 'in',
2155
- 'instanceof',
2156
- 'let',
2157
- 'new',
2158
- 'null',
2159
- 'return',
2160
- 'super',
2161
- 'switch',
2162
- 'this',
2163
- 'throw',
2164
- 'true',
2165
- 'try',
2166
- 'typeof',
2167
- 'var',
2168
- 'void',
2169
- 'while',
2170
- 'with',
2171
- 'yield',
2172
- // Common globals
2173
- 'console',
2174
- 'JSON',
2175
- 'Error',
2176
- // Typescript types
2177
- 'string',
2178
- 'number',
2179
- 'boolean',
2180
- 'object',
2181
- 'symbol',
2182
- // Common methods on built-in objects
2183
- 'test',
2184
- 'match',
2185
- 'exec',
2186
- 'replace',
2187
- 'search',
2188
- 'split',
2189
- ]);
2190
- try {
2191
- // Note: Extract variables from template literals like ${variable}
2192
- const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
2193
- let match;
2194
- while ((match = templateRegex.exec(script)) !== null) {
2195
- const varName = match[1];
2196
- if (!exclude.has(varName)) {
2197
- variables.add(varName);
2198
- }
2199
- }
2200
- // Note: Process the script to handle normal variable usage
2201
- const processedScript = script
2202
- .replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
2203
- .replace(/"(?:\\.|[^"\\])*"/g, '""')
2204
- .replace(/`(?:\\.|[^`\\])*`/g, '``')
2205
- .replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
2206
- // Note: Find identifiers in function arguments
2207
- const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
2208
- const funcNames = new Set();
2209
- while ((match = funcArgRegex.exec(processedScript)) !== null) {
2210
- funcNames.add(match[1]);
2211
- }
2212
- // Find variable declarations to exclude them
2213
- const declaredVars = new Set();
2214
- const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
2215
- while ((match = declRegex.exec(processedScript)) !== null) {
2216
- declaredVars.add(match[2]);
2217
- }
2218
- // Note: Find identifiers in the script
2219
- const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
2220
- while ((match = identifierRegex.exec(processedScript)) !== null) {
2221
- const name = match[1];
2222
- // Add if not excluded, not a function name, and not a declared variable
2223
- if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
2224
- variables.add(name);
2225
- }
2226
- }
2227
- }
2228
- catch (error) {
2229
- if (!(error instanceof Error)) {
2230
- throw error;
2231
- }
2232
- throw new ParseError(spaceTrim((block) => `
2233
- Can not extract variables from the script
2234
- ${block(error.stack || error.message)}
2235
-
2236
- Found variables:
2237
- ${Array.from(variables)
2238
- .map((variableName, i) => `${i + 1}) ${variableName}`)
2239
- .join('\n')}
2240
-
2241
-
2242
- The script:
2243
-
2244
- \`\`\`javascript
2245
- ${block(script)}
2246
- \`\`\`
2247
- `));
2248
- }
2249
- return variables;
2250
- }
2251
- /**
2252
- * TODO: [🔣] Support for multiple languages - python, java,...
2253
- */
2254
-
2255
2119
  /**
2256
2120
  * Parses the task and returns the set of all used parameters
2257
2121
  *
@@ -2261,7 +2125,7 @@ function extractVariablesFromScript(script) {
2261
2125
  * @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
2262
2126
  */
2263
2127
  function extractParameterNamesFromTask(task) {
2264
- const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
2128
+ const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
2265
2129
  const parameterNames = new Set();
2266
2130
  for (const parameterName of [
2267
2131
  ...extractParameterNames(title),
@@ -2271,11 +2135,14 @@ function extractParameterNamesFromTask(task) {
2271
2135
  ]) {
2272
2136
  parameterNames.add(parameterName);
2273
2137
  }
2138
+ /*/
2139
+ // TODO: [🙊] Fix `extractVariablesFromScript` or delete
2274
2140
  if (taskType === 'SCRIPT_TASK') {
2275
2141
  for (const parameterName of extractVariablesFromScript(content)) {
2276
2142
  parameterNames.add(parameterName);
2277
2143
  }
2278
2144
  }
2145
+ /**/
2279
2146
  for (const jokerName of jokerParameterNames || []) {
2280
2147
  parameterNames.add(jokerName);
2281
2148
  }
@@ -10065,6 +9932,8 @@ class JavascriptEvalExecutionTools {
10065
9932
  // Note: Custom functions are exposed to the current scope as variables
10066
9933
  `const ${functionName} = customFunctions.${functionName};`)
10067
9934
  .join('\n');
9935
+ script = templateParameters(script, parameters);
9936
+ // <- Note: [🙊]
10068
9937
  const statementToEvaluate = spaceTrim((block) => `
10069
9938
 
10070
9939
  // Build-in functions: