@promptbook/cli 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 +23 -154
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/utils.index.d.ts +0 -2
- package/package.json +1 -1
- package/umd/index.umd.js +23 -154
- 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
|
@@ -2,7 +2,6 @@ import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
|
|
|
2
2
|
import { VALUE_STRINGS } from '../config';
|
|
3
3
|
import { SMALL_NUMBER } from '../config';
|
|
4
4
|
import { renderPromptbookMermaid } from '../conversion/prettify/renderPipelineMermaidOptions';
|
|
5
|
-
import { extractVariablesFromScript } from '../conversion/utils/extractVariablesFromScript';
|
|
6
5
|
import { deserializeError } from '../errors/utils/deserializeError';
|
|
7
6
|
import { serializeError } from '../errors/utils/serializeError';
|
|
8
7
|
import { forEachAsync } from '../execution/utils/forEachAsync';
|
|
@@ -84,7 +83,6 @@ export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
|
|
|
84
83
|
export { VALUE_STRINGS };
|
|
85
84
|
export { SMALL_NUMBER };
|
|
86
85
|
export { renderPromptbookMermaid };
|
|
87
|
-
export { extractVariablesFromScript };
|
|
88
86
|
export { deserializeError };
|
|
89
87
|
export { serializeError };
|
|
90
88
|
export { forEachAsync };
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
* @generated
|
|
55
55
|
* @see https://github.com/webgptorg/promptbook
|
|
56
56
|
*/
|
|
57
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.86.
|
|
57
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.86.30';
|
|
58
58
|
/**
|
|
59
59
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
60
60
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -3247,158 +3247,6 @@
|
|
|
3247
3247
|
* TODO: [🕌] When more than 2 functionalities, split into separate functions
|
|
3248
3248
|
*/
|
|
3249
3249
|
|
|
3250
|
-
/**
|
|
3251
|
-
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
3252
|
-
*
|
|
3253
|
-
* @public exported from `@promptbook/core`
|
|
3254
|
-
*/
|
|
3255
|
-
class ParseError extends Error {
|
|
3256
|
-
constructor(message) {
|
|
3257
|
-
super(message);
|
|
3258
|
-
this.name = 'ParseError';
|
|
3259
|
-
Object.setPrototypeOf(this, ParseError.prototype);
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
/**
|
|
3263
|
-
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
3264
|
-
*/
|
|
3265
|
-
|
|
3266
|
-
/**
|
|
3267
|
-
* Extract all used variable names from ginen JavaScript/TypeScript script
|
|
3268
|
-
*
|
|
3269
|
-
* @param script JavaScript/TypeScript script
|
|
3270
|
-
* @returns Set of variable names
|
|
3271
|
-
* @throws {ParseError} if the script is invalid
|
|
3272
|
-
* @public exported from `@promptbook/utils` <- Note: [👖] This is usable elsewhere than in Promptbook, so keeping in utils
|
|
3273
|
-
*/
|
|
3274
|
-
function extractVariablesFromScript(script) {
|
|
3275
|
-
if (script.trim() === '') {
|
|
3276
|
-
return new Set();
|
|
3277
|
-
}
|
|
3278
|
-
const variables = new Set();
|
|
3279
|
-
// JS keywords and builtins to exclude
|
|
3280
|
-
const exclude = new Set([
|
|
3281
|
-
// Keywords
|
|
3282
|
-
'break',
|
|
3283
|
-
'case',
|
|
3284
|
-
'catch',
|
|
3285
|
-
'class',
|
|
3286
|
-
'const',
|
|
3287
|
-
'continue',
|
|
3288
|
-
'debugger',
|
|
3289
|
-
'default',
|
|
3290
|
-
'delete',
|
|
3291
|
-
'do',
|
|
3292
|
-
'else',
|
|
3293
|
-
'export',
|
|
3294
|
-
'extends',
|
|
3295
|
-
'false',
|
|
3296
|
-
'finally',
|
|
3297
|
-
'for',
|
|
3298
|
-
'function',
|
|
3299
|
-
'if',
|
|
3300
|
-
'import',
|
|
3301
|
-
'in',
|
|
3302
|
-
'instanceof',
|
|
3303
|
-
'let',
|
|
3304
|
-
'new',
|
|
3305
|
-
'null',
|
|
3306
|
-
'return',
|
|
3307
|
-
'super',
|
|
3308
|
-
'switch',
|
|
3309
|
-
'this',
|
|
3310
|
-
'throw',
|
|
3311
|
-
'true',
|
|
3312
|
-
'try',
|
|
3313
|
-
'typeof',
|
|
3314
|
-
'var',
|
|
3315
|
-
'void',
|
|
3316
|
-
'while',
|
|
3317
|
-
'with',
|
|
3318
|
-
'yield',
|
|
3319
|
-
// Common globals
|
|
3320
|
-
'console',
|
|
3321
|
-
'JSON',
|
|
3322
|
-
'Error',
|
|
3323
|
-
// Typescript types
|
|
3324
|
-
'string',
|
|
3325
|
-
'number',
|
|
3326
|
-
'boolean',
|
|
3327
|
-
'object',
|
|
3328
|
-
'symbol',
|
|
3329
|
-
// Common methods on built-in objects
|
|
3330
|
-
'test',
|
|
3331
|
-
'match',
|
|
3332
|
-
'exec',
|
|
3333
|
-
'replace',
|
|
3334
|
-
'search',
|
|
3335
|
-
'split',
|
|
3336
|
-
]);
|
|
3337
|
-
try {
|
|
3338
|
-
// Note: Extract variables from template literals like ${variable}
|
|
3339
|
-
const templateRegex = /\$\{([a-zA-Z_$][a-zA-Z0-9_$]*)\}/g;
|
|
3340
|
-
let match;
|
|
3341
|
-
while ((match = templateRegex.exec(script)) !== null) {
|
|
3342
|
-
const varName = match[1];
|
|
3343
|
-
if (!exclude.has(varName)) {
|
|
3344
|
-
variables.add(varName);
|
|
3345
|
-
}
|
|
3346
|
-
}
|
|
3347
|
-
// Note: Process the script to handle normal variable usage
|
|
3348
|
-
const processedScript = script
|
|
3349
|
-
.replace(/'(?:\\.|[^'\\])*'/g, "''") // <- Note: Remove string literals
|
|
3350
|
-
.replace(/"(?:\\.|[^"\\])*"/g, '""')
|
|
3351
|
-
.replace(/`(?:\\.|[^`\\])*`/g, '``')
|
|
3352
|
-
.replace(/\/(?:\\.|[^/\\])*\/[gimsuy]*/g, '{}'); // <- Note: Remove regex literals
|
|
3353
|
-
// Note: Find identifiers in function arguments
|
|
3354
|
-
const funcArgRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/g;
|
|
3355
|
-
const funcNames = new Set();
|
|
3356
|
-
while ((match = funcArgRegex.exec(processedScript)) !== null) {
|
|
3357
|
-
funcNames.add(match[1]);
|
|
3358
|
-
}
|
|
3359
|
-
// Find variable declarations to exclude them
|
|
3360
|
-
const declaredVars = new Set();
|
|
3361
|
-
const declRegex = /\b(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
3362
|
-
while ((match = declRegex.exec(processedScript)) !== null) {
|
|
3363
|
-
declaredVars.add(match[2]);
|
|
3364
|
-
}
|
|
3365
|
-
// Note: Find identifiers in the script
|
|
3366
|
-
const identifierRegex = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g;
|
|
3367
|
-
while ((match = identifierRegex.exec(processedScript)) !== null) {
|
|
3368
|
-
const name = match[1];
|
|
3369
|
-
// Add if not excluded, not a function name, and not a declared variable
|
|
3370
|
-
if (!exclude.has(name) && !funcNames.has(name) && !declaredVars.has(name)) {
|
|
3371
|
-
variables.add(name);
|
|
3372
|
-
}
|
|
3373
|
-
}
|
|
3374
|
-
}
|
|
3375
|
-
catch (error) {
|
|
3376
|
-
if (!(error instanceof Error)) {
|
|
3377
|
-
throw error;
|
|
3378
|
-
}
|
|
3379
|
-
throw new ParseError(spaceTrim__default["default"]((block) => `
|
|
3380
|
-
Can not extract variables from the script
|
|
3381
|
-
${block(error.stack || error.message)}
|
|
3382
|
-
|
|
3383
|
-
Found variables:
|
|
3384
|
-
${Array.from(variables)
|
|
3385
|
-
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
3386
|
-
.join('\n')}
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
The script:
|
|
3390
|
-
|
|
3391
|
-
\`\`\`javascript
|
|
3392
|
-
${block(script)}
|
|
3393
|
-
\`\`\`
|
|
3394
|
-
`));
|
|
3395
|
-
}
|
|
3396
|
-
return variables;
|
|
3397
|
-
}
|
|
3398
|
-
/**
|
|
3399
|
-
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
3400
|
-
*/
|
|
3401
|
-
|
|
3402
3250
|
/**
|
|
3403
3251
|
* This error indicates problems parsing the format value
|
|
3404
3252
|
*
|
|
@@ -3515,6 +3363,22 @@
|
|
|
3515
3363
|
}
|
|
3516
3364
|
}
|
|
3517
3365
|
|
|
3366
|
+
/**
|
|
3367
|
+
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
3368
|
+
*
|
|
3369
|
+
* @public exported from `@promptbook/core`
|
|
3370
|
+
*/
|
|
3371
|
+
class ParseError extends Error {
|
|
3372
|
+
constructor(message) {
|
|
3373
|
+
super(message);
|
|
3374
|
+
this.name = 'ParseError';
|
|
3375
|
+
Object.setPrototypeOf(this, ParseError.prototype);
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
/**
|
|
3379
|
+
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
3380
|
+
*/
|
|
3381
|
+
|
|
3518
3382
|
/**
|
|
3519
3383
|
* This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
|
|
3520
3384
|
*
|
|
@@ -4695,6 +4559,8 @@
|
|
|
4695
4559
|
// Note: Custom functions are exposed to the current scope as variables
|
|
4696
4560
|
`const ${functionName} = customFunctions.${functionName};`)
|
|
4697
4561
|
.join('\n');
|
|
4562
|
+
script = templateParameters(script, parameters);
|
|
4563
|
+
// <- Note: [🙊]
|
|
4698
4564
|
const statementToEvaluate = spaceTrim__default["default"]((block) => `
|
|
4699
4565
|
|
|
4700
4566
|
// Build-in functions:
|
|
@@ -5603,7 +5469,7 @@
|
|
|
5603
5469
|
* @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
|
|
5604
5470
|
*/
|
|
5605
5471
|
function extractParameterNamesFromTask(task) {
|
|
5606
|
-
const { title, description, taskType
|
|
5472
|
+
const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
|
|
5607
5473
|
const parameterNames = new Set();
|
|
5608
5474
|
for (const parameterName of [
|
|
5609
5475
|
...extractParameterNames(title),
|
|
@@ -5613,11 +5479,14 @@
|
|
|
5613
5479
|
]) {
|
|
5614
5480
|
parameterNames.add(parameterName);
|
|
5615
5481
|
}
|
|
5482
|
+
/*/
|
|
5483
|
+
// TODO: [🙊] Fix `extractVariablesFromScript` or delete
|
|
5616
5484
|
if (taskType === 'SCRIPT_TASK') {
|
|
5617
5485
|
for (const parameterName of extractVariablesFromScript(content)) {
|
|
5618
5486
|
parameterNames.add(parameterName);
|
|
5619
5487
|
}
|
|
5620
5488
|
}
|
|
5489
|
+
/**/
|
|
5621
5490
|
for (const jokerName of jokerParameterNames || []) {
|
|
5622
5491
|
parameterNames.add(jokerName);
|
|
5623
5492
|
}
|