@promptbook/pdf 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 CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
 
25
25
 
26
+ <blockquote style="color: #ff8811">
27
+ <b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
28
+ </blockquote>
29
+
26
30
  ## 📦 Package `@promptbook/pdf`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -251,7 +255,7 @@ Or you can install them separately:
251
255
  - ⭐ **[@promptbook/utils](https://www.npmjs.com/package/@promptbook/utils)** - Utility functions used in the library but also useful for individual use in preprocessing and postprocessing LLM inputs and outputs
252
256
  - **[@promptbook/markdown-utils](https://www.npmjs.com/package/@promptbook/markdown-utils)** - Utility functions used for processing markdown
253
257
  - _(Not finished)_ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizard for creating+running promptbooks in single line
254
- - **[@promptbook/execute-javascript](https://www.npmjs.com/package/@promptbook/execute-javascript)** - Execution tools for javascript inside promptbooks
258
+ - **[@promptbook/javascript](https://www.npmjs.com/package/@promptbook/javascript)** - Execution tools for javascript inside promptbooks
255
259
  - **[@promptbook/openai](https://www.npmjs.com/package/@promptbook/openai)** - Execution tools for OpenAI API, wrapper around OpenAI SDK
256
260
  - **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
257
261
  - **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
@@ -407,8 +411,6 @@ Promptbook project is under [BUSL 1.1 is an SPDX license](https://spdx.org/licen
407
411
 
408
412
  See [TODO.md](./TODO.md)
409
413
 
410
-
411
-
412
414
  ## 🤝 Partners
413
415
 
414
416
  <div style="display: flex; align-items: center; gap: 20px;">
package/esm/index.es.js CHANGED
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.86.30';
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
@@ -3648,6 +3648,83 @@ function valueToString(value) {
3648
3648
  }
3649
3649
  }
3650
3650
 
3651
+ /**
3652
+ * Parses the given script and returns the list of all used variables that are not defined in the script
3653
+ *
3654
+ * @param script from which to extract the variables
3655
+ * @returns the list of variable names
3656
+ * @throws {ParseError} if the script is invalid
3657
+ * @public exported from `@promptbook/javascript`
3658
+ */
3659
+ function extractVariablesFromJavascript(script) {
3660
+ const variables = new Set();
3661
+ const originalScript = script;
3662
+ script = `(()=>{${script}})()`;
3663
+ try {
3664
+ for (let i = 0; i < LOOP_LIMIT; i++)
3665
+ try {
3666
+ eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
3667
+ }
3668
+ catch (error) {
3669
+ if (!(error instanceof ReferenceError)) {
3670
+ throw error;
3671
+ }
3672
+ /*
3673
+ Note: Parsing the error
3674
+ 🌟 Most devices:
3675
+ [PipelineUrlError: thing is not defined]
3676
+
3677
+ 🍏 iPhone`s Safari:
3678
+ [PipelineUrlError: Can't find variable: thing]
3679
+ */
3680
+ let variableName = undefined;
3681
+ if (error.message.startsWith(`Can't`)) {
3682
+ // 🍏 Case
3683
+ variableName = error.message.split(' ').pop();
3684
+ }
3685
+ else {
3686
+ // 🌟 Case
3687
+ variableName = error.message.split(' ').shift();
3688
+ }
3689
+ if (variableName === undefined) {
3690
+ throw error;
3691
+ }
3692
+ if (script.includes(variableName + '(')) {
3693
+ script = `const ${variableName} = ()=>'';` + script;
3694
+ }
3695
+ else {
3696
+ variables.add(variableName);
3697
+ script = `const ${variableName} = '';` + script;
3698
+ }
3699
+ }
3700
+ }
3701
+ catch (error) {
3702
+ if (!(error instanceof Error)) {
3703
+ throw error;
3704
+ }
3705
+ throw new ParseError(spaceTrim$1((block) => `
3706
+ Can not extract variables from the script
3707
+ ${block(error.stack || error.message)}
3708
+
3709
+ Found variables:
3710
+ ${Array.from(variables)
3711
+ .map((variableName, i) => `${i + 1}) ${variableName}`)
3712
+ .join('\n')}
3713
+
3714
+
3715
+ The script:
3716
+
3717
+ \`\`\`javascript
3718
+ ${block(originalScript)}
3719
+ \`\`\`
3720
+ `));
3721
+ }
3722
+ return variables;
3723
+ }
3724
+ /**
3725
+ * TODO: [🔣] Support for multiple languages - python, java,...
3726
+ */
3727
+
3651
3728
  /**
3652
3729
  * Parses the task and returns the set of all used parameters
3653
3730
  *
@@ -3657,24 +3734,26 @@ function valueToString(value) {
3657
3734
  * @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
3658
3735
  */
3659
3736
  function extractParameterNamesFromTask(task) {
3660
- const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
3737
+ const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
3661
3738
  const parameterNames = new Set();
3739
+ let contentParameters;
3740
+ if (taskType !== 'SCRIPT_TASK') {
3741
+ contentParameters = extractParameterNames(content);
3742
+ }
3743
+ else {
3744
+ // TODO: What if script is not javascript?
3745
+ // const { contentLanguage } = task;
3746
+ // if (contentLanguage !== 'javascript') {
3747
+ contentParameters = extractVariablesFromJavascript(content);
3748
+ }
3662
3749
  for (const parameterName of [
3663
3750
  ...extractParameterNames(title),
3664
3751
  ...extractParameterNames(description || ''),
3665
- ...extractParameterNames(content),
3752
+ ...contentParameters,
3666
3753
  ...extractParameterNames(preparedContent || ''),
3667
3754
  ]) {
3668
3755
  parameterNames.add(parameterName);
3669
3756
  }
3670
- /*/
3671
- // TODO: [🙊] Fix `extractVariablesFromScript` or delete
3672
- if (taskType === 'SCRIPT_TASK') {
3673
- for (const parameterName of extractVariablesFromScript(content)) {
3674
- parameterNames.add(parameterName);
3675
- }
3676
- }
3677
- /**/
3678
3757
  for (const jokerName of jokerParameterNames || []) {
3679
3758
  parameterNames.add(jokerName);
3680
3759
  }