@promptbook/documents 0.86.30 → 0.88.0-1
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/README.md +5 -3
- package/esm/index.es.js +90 -11
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/{execute-javascript.index.d.ts → javascript.index.d.ts} +2 -0
- package/esm/typings/src/_packages/node.index.d.ts +2 -0
- package/esm/typings/src/scrapers/_common/register/$provideScriptingForNode.d.ts +11 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.test.d.ts +4 -0
- package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.d.ts +14 -0
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.test.d.ts +1 -0
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromScript.test.d.ts +1 -0
- package/package.json +2 -2
- package/umd/index.umd.js +90 -11
- package/umd/index.umd.js.map +1 -1
|
@@ -2,7 +2,9 @@ import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
|
|
|
2
2
|
import { JavascriptEvalExecutionTools } from '../scripting/javascript/JavascriptEvalExecutionTools';
|
|
3
3
|
import { JavascriptExecutionTools } from '../scripting/javascript/JavascriptExecutionTools';
|
|
4
4
|
import { POSTPROCESSING_FUNCTIONS } from '../scripting/javascript/postprocessing-functions';
|
|
5
|
+
import { extractVariablesFromJavascript } from '../scripting/javascript/utils/extractVariablesFromJavascript';
|
|
5
6
|
export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
|
|
6
7
|
export { JavascriptEvalExecutionTools };
|
|
7
8
|
export { JavascriptExecutionTools };
|
|
8
9
|
export { POSTPROCESSING_FUNCTIONS };
|
|
10
|
+
export { extractVariablesFromJavascript };
|
|
@@ -6,6 +6,7 @@ import { $provideLlmToolsConfigurationFromEnv } from '../llm-providers/_common/r
|
|
|
6
6
|
import { $provideLlmToolsFromEnv } from '../llm-providers/_common/register/$provideLlmToolsFromEnv';
|
|
7
7
|
import { $provideFilesystemForNode } from '../scrapers/_common/register/$provideFilesystemForNode';
|
|
8
8
|
import { $provideScrapersForNode } from '../scrapers/_common/register/$provideScrapersForNode';
|
|
9
|
+
import { $provideScriptingForNode } from '../scrapers/_common/register/$provideScriptingForNode';
|
|
9
10
|
import { FileCacheStorage } from '../storage/file-cache-storage/FileCacheStorage';
|
|
10
11
|
import { $execCommand } from '../utils/execCommand/$execCommand';
|
|
11
12
|
import { $execCommands } from '../utils/execCommand/$execCommands';
|
|
@@ -17,6 +18,7 @@ export { $provideLlmToolsConfigurationFromEnv };
|
|
|
17
18
|
export { $provideLlmToolsFromEnv };
|
|
18
19
|
export { $provideFilesystemForNode };
|
|
19
20
|
export { $provideScrapersForNode };
|
|
21
|
+
export { $provideScriptingForNode };
|
|
20
22
|
export { FileCacheStorage };
|
|
21
23
|
export { $execCommand };
|
|
22
24
|
export { $execCommands };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ScriptExecutionTools } from '../../../execution/ScriptExecutionTools';
|
|
2
|
+
import type { PrepareAndScrapeOptions } from '../../../prepare/PrepareAndScrapeOptions';
|
|
3
|
+
/**
|
|
4
|
+
* Provides script execution tools
|
|
5
|
+
*
|
|
6
|
+
* @public exported from `@promptbook/node`
|
|
7
|
+
*/
|
|
8
|
+
export declare function $provideScriptingForNode(options?: PrepareAndScrapeOptions): Promise<ReadonlyArray<ScriptExecutionTools>>;
|
|
9
|
+
/**
|
|
10
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
11
|
+
*/
|
|
@@ -6,7 +6,7 @@ import type { JavascriptExecutionToolsOptions } from './JavascriptExecutionTools
|
|
|
6
6
|
* Warning: It is used for testing and mocking
|
|
7
7
|
* **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
|
|
8
8
|
*
|
|
9
|
-
* @public exported from `@promptbook/
|
|
9
|
+
* @public exported from `@promptbook/javascript`
|
|
10
10
|
*/
|
|
11
11
|
export declare class JavascriptEvalExecutionTools implements ScriptExecutionTools {
|
|
12
12
|
protected readonly options: JavascriptExecutionToolsOptions;
|
|
@@ -3,6 +3,6 @@ import { JavascriptEvalExecutionTools } from './JavascriptEvalExecutionTools';
|
|
|
3
3
|
* Placeholder for better implementation of JavascriptExecutionTools - some propper sandboxing
|
|
4
4
|
*
|
|
5
5
|
* @alias JavascriptExecutionTools
|
|
6
|
-
* @public exported from `@promptbook/
|
|
6
|
+
* @public exported from `@promptbook/javascript`
|
|
7
7
|
*/
|
|
8
8
|
export declare const JavascriptExecutionTools: typeof JavascriptEvalExecutionTools;
|
|
@@ -20,7 +20,7 @@ import { unwrapResult } from '../../utils/unwrapResult';
|
|
|
20
20
|
/**
|
|
21
21
|
* @@@
|
|
22
22
|
*
|
|
23
|
-
* @public exported from `@promptbook/
|
|
23
|
+
* @public exported from `@promptbook/javascript`
|
|
24
24
|
*/
|
|
25
25
|
export declare const POSTPROCESSING_FUNCTIONS: {
|
|
26
26
|
spaceTrim: typeof spaceTrim;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { string_javascript } from '../../../types/typeAliases';
|
|
2
|
+
import type { string_javascript_name } from '../../../types/typeAliases';
|
|
3
|
+
/**
|
|
4
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
5
|
+
*
|
|
6
|
+
* @param script from which to extract the variables
|
|
7
|
+
* @returns the list of variable names
|
|
8
|
+
* @throws {ParseError} if the script is invalid
|
|
9
|
+
* @public exported from `@promptbook/javascript`
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractVariablesFromJavascript(script: string_javascript): Set<string_javascript_name>;
|
|
12
|
+
/**
|
|
13
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
14
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/documents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.88.0-1",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"module": "./esm/index.es.js",
|
|
48
48
|
"typings": "./esm/typings/src/_packages/documents.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.
|
|
50
|
+
"@promptbook/core": "0.88.0-1"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"colors": "1.4.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-1';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -3793,6 +3793,83 @@
|
|
|
3793
3793
|
}
|
|
3794
3794
|
}
|
|
3795
3795
|
|
|
3796
|
+
/**
|
|
3797
|
+
* Parses the given script and returns the list of all used variables that are not defined in the script
|
|
3798
|
+
*
|
|
3799
|
+
* @param script from which to extract the variables
|
|
3800
|
+
* @returns the list of variable names
|
|
3801
|
+
* @throws {ParseError} if the script is invalid
|
|
3802
|
+
* @public exported from `@promptbook/javascript`
|
|
3803
|
+
*/
|
|
3804
|
+
function extractVariablesFromJavascript(script) {
|
|
3805
|
+
const variables = new Set();
|
|
3806
|
+
const originalScript = script;
|
|
3807
|
+
script = `(()=>{${script}})()`;
|
|
3808
|
+
try {
|
|
3809
|
+
for (let i = 0; i < LOOP_LIMIT; i++)
|
|
3810
|
+
try {
|
|
3811
|
+
eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
|
|
3812
|
+
}
|
|
3813
|
+
catch (error) {
|
|
3814
|
+
if (!(error instanceof ReferenceError)) {
|
|
3815
|
+
throw error;
|
|
3816
|
+
}
|
|
3817
|
+
/*
|
|
3818
|
+
Note: Parsing the error
|
|
3819
|
+
🌟 Most devices:
|
|
3820
|
+
[PipelineUrlError: thing is not defined]
|
|
3821
|
+
|
|
3822
|
+
🍏 iPhone`s Safari:
|
|
3823
|
+
[PipelineUrlError: Can't find variable: thing]
|
|
3824
|
+
*/
|
|
3825
|
+
let variableName = undefined;
|
|
3826
|
+
if (error.message.startsWith(`Can't`)) {
|
|
3827
|
+
// 🍏 Case
|
|
3828
|
+
variableName = error.message.split(' ').pop();
|
|
3829
|
+
}
|
|
3830
|
+
else {
|
|
3831
|
+
// 🌟 Case
|
|
3832
|
+
variableName = error.message.split(' ').shift();
|
|
3833
|
+
}
|
|
3834
|
+
if (variableName === undefined) {
|
|
3835
|
+
throw error;
|
|
3836
|
+
}
|
|
3837
|
+
if (script.includes(variableName + '(')) {
|
|
3838
|
+
script = `const ${variableName} = ()=>'';` + script;
|
|
3839
|
+
}
|
|
3840
|
+
else {
|
|
3841
|
+
variables.add(variableName);
|
|
3842
|
+
script = `const ${variableName} = '';` + script;
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
catch (error) {
|
|
3847
|
+
if (!(error instanceof Error)) {
|
|
3848
|
+
throw error;
|
|
3849
|
+
}
|
|
3850
|
+
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
3851
|
+
Can not extract variables from the script
|
|
3852
|
+
${block(error.stack || error.message)}
|
|
3853
|
+
|
|
3854
|
+
Found variables:
|
|
3855
|
+
${Array.from(variables)
|
|
3856
|
+
.map((variableName, i) => `${i + 1}) ${variableName}`)
|
|
3857
|
+
.join('\n')}
|
|
3858
|
+
|
|
3859
|
+
|
|
3860
|
+
The script:
|
|
3861
|
+
|
|
3862
|
+
\`\`\`javascript
|
|
3863
|
+
${block(originalScript)}
|
|
3864
|
+
\`\`\`
|
|
3865
|
+
`));
|
|
3866
|
+
}
|
|
3867
|
+
return variables;
|
|
3868
|
+
}
|
|
3869
|
+
/**
|
|
3870
|
+
* TODO: [🔣] Support for multiple languages - python, java,...
|
|
3871
|
+
*/
|
|
3872
|
+
|
|
3796
3873
|
/**
|
|
3797
3874
|
* Parses the task and returns the set of all used parameters
|
|
3798
3875
|
*
|
|
@@ -3802,24 +3879,26 @@
|
|
|
3802
3879
|
* @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
|
|
3803
3880
|
*/
|
|
3804
3881
|
function extractParameterNamesFromTask(task) {
|
|
3805
|
-
const { title, description,
|
|
3882
|
+
const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
|
|
3806
3883
|
const parameterNames = new Set();
|
|
3884
|
+
let contentParameters;
|
|
3885
|
+
if (taskType !== 'SCRIPT_TASK') {
|
|
3886
|
+
contentParameters = extractParameterNames(content);
|
|
3887
|
+
}
|
|
3888
|
+
else {
|
|
3889
|
+
// TODO: What if script is not javascript?
|
|
3890
|
+
// const { contentLanguage } = task;
|
|
3891
|
+
// if (contentLanguage !== 'javascript') {
|
|
3892
|
+
contentParameters = extractVariablesFromJavascript(content);
|
|
3893
|
+
}
|
|
3807
3894
|
for (const parameterName of [
|
|
3808
3895
|
...extractParameterNames(title),
|
|
3809
3896
|
...extractParameterNames(description || ''),
|
|
3810
|
-
...
|
|
3897
|
+
...contentParameters,
|
|
3811
3898
|
...extractParameterNames(preparedContent || ''),
|
|
3812
3899
|
]) {
|
|
3813
3900
|
parameterNames.add(parameterName);
|
|
3814
3901
|
}
|
|
3815
|
-
/*/
|
|
3816
|
-
// TODO: [🙊] Fix `extractVariablesFromScript` or delete
|
|
3817
|
-
if (taskType === 'SCRIPT_TASK') {
|
|
3818
|
-
for (const parameterName of extractVariablesFromScript(content)) {
|
|
3819
|
-
parameterNames.add(parameterName);
|
|
3820
|
-
}
|
|
3821
|
-
}
|
|
3822
|
-
/**/
|
|
3823
3902
|
for (const jokerName of jokerParameterNames || []) {
|
|
3824
3903
|
parameterNames.add(jokerName);
|
|
3825
3904
|
}
|