@promptbook/markitdown 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/markitdown`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -249,7 +253,7 @@ Or you can install them separately:
249
253
  - ⭐ **[@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
250
254
  - **[@promptbook/markdown-utils](https://www.npmjs.com/package/@promptbook/markdown-utils)** - Utility functions used for processing markdown
251
255
  - _(Not finished)_ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizard for creating+running promptbooks in single line
252
- - **[@promptbook/execute-javascript](https://www.npmjs.com/package/@promptbook/execute-javascript)** - Execution tools for javascript inside promptbooks
256
+ - **[@promptbook/javascript](https://www.npmjs.com/package/@promptbook/javascript)** - Execution tools for javascript inside promptbooks
253
257
  - **[@promptbook/openai](https://www.npmjs.com/package/@promptbook/openai)** - Execution tools for OpenAI API, wrapper around OpenAI SDK
254
258
  - **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
255
259
  - **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
@@ -405,8 +409,6 @@ Promptbook project is under [BUSL 1.1 is an SPDX license](https://spdx.org/licen
405
409
 
406
410
  See [TODO.md](./TODO.md)
407
411
 
408
-
409
-
410
412
  ## 🤝 Partners
411
413
 
412
414
  <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
@@ -3635,6 +3635,83 @@ function valueToString(value) {
3635
3635
  }
3636
3636
  }
3637
3637
 
3638
+ /**
3639
+ * Parses the given script and returns the list of all used variables that are not defined in the script
3640
+ *
3641
+ * @param script from which to extract the variables
3642
+ * @returns the list of variable names
3643
+ * @throws {ParseError} if the script is invalid
3644
+ * @public exported from `@promptbook/javascript`
3645
+ */
3646
+ function extractVariablesFromJavascript(script) {
3647
+ const variables = new Set();
3648
+ const originalScript = script;
3649
+ script = `(()=>{${script}})()`;
3650
+ try {
3651
+ for (let i = 0; i < LOOP_LIMIT; i++)
3652
+ try {
3653
+ eval(script); // <- TODO: Use `JavascriptExecutionTools.execute` here
3654
+ }
3655
+ catch (error) {
3656
+ if (!(error instanceof ReferenceError)) {
3657
+ throw error;
3658
+ }
3659
+ /*
3660
+ Note: Parsing the error
3661
+ 🌟 Most devices:
3662
+ [PipelineUrlError: thing is not defined]
3663
+
3664
+ 🍏 iPhone`s Safari:
3665
+ [PipelineUrlError: Can't find variable: thing]
3666
+ */
3667
+ let variableName = undefined;
3668
+ if (error.message.startsWith(`Can't`)) {
3669
+ // 🍏 Case
3670
+ variableName = error.message.split(' ').pop();
3671
+ }
3672
+ else {
3673
+ // 🌟 Case
3674
+ variableName = error.message.split(' ').shift();
3675
+ }
3676
+ if (variableName === undefined) {
3677
+ throw error;
3678
+ }
3679
+ if (script.includes(variableName + '(')) {
3680
+ script = `const ${variableName} = ()=>'';` + script;
3681
+ }
3682
+ else {
3683
+ variables.add(variableName);
3684
+ script = `const ${variableName} = '';` + script;
3685
+ }
3686
+ }
3687
+ }
3688
+ catch (error) {
3689
+ if (!(error instanceof Error)) {
3690
+ throw error;
3691
+ }
3692
+ throw new ParseError(spaceTrim$1((block) => `
3693
+ Can not extract variables from the script
3694
+ ${block(error.stack || error.message)}
3695
+
3696
+ Found variables:
3697
+ ${Array.from(variables)
3698
+ .map((variableName, i) => `${i + 1}) ${variableName}`)
3699
+ .join('\n')}
3700
+
3701
+
3702
+ The script:
3703
+
3704
+ \`\`\`javascript
3705
+ ${block(originalScript)}
3706
+ \`\`\`
3707
+ `));
3708
+ }
3709
+ return variables;
3710
+ }
3711
+ /**
3712
+ * TODO: [🔣] Support for multiple languages - python, java,...
3713
+ */
3714
+
3638
3715
  /**
3639
3716
  * Parses the task and returns the set of all used parameters
3640
3717
  *
@@ -3644,24 +3721,26 @@ function valueToString(value) {
3644
3721
  * @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
3645
3722
  */
3646
3723
  function extractParameterNamesFromTask(task) {
3647
- const { title, description, /* [🙊] taskType,*/ content, preparedContent, jokerParameterNames, foreach } = task;
3724
+ const { title, description, taskType, content, preparedContent, jokerParameterNames, foreach } = task;
3648
3725
  const parameterNames = new Set();
3726
+ let contentParameters;
3727
+ if (taskType !== 'SCRIPT_TASK') {
3728
+ contentParameters = extractParameterNames(content);
3729
+ }
3730
+ else {
3731
+ // TODO: What if script is not javascript?
3732
+ // const { contentLanguage } = task;
3733
+ // if (contentLanguage !== 'javascript') {
3734
+ contentParameters = extractVariablesFromJavascript(content);
3735
+ }
3649
3736
  for (const parameterName of [
3650
3737
  ...extractParameterNames(title),
3651
3738
  ...extractParameterNames(description || ''),
3652
- ...extractParameterNames(content),
3739
+ ...contentParameters,
3653
3740
  ...extractParameterNames(preparedContent || ''),
3654
3741
  ]) {
3655
3742
  parameterNames.add(parameterName);
3656
3743
  }
3657
- /*/
3658
- // TODO: [🙊] Fix `extractVariablesFromScript` or delete
3659
- if (taskType === 'SCRIPT_TASK') {
3660
- for (const parameterName of extractVariablesFromScript(content)) {
3661
- parameterNames.add(parameterName);
3662
- }
3663
- }
3664
- /**/
3665
3744
  for (const jokerName of jokerParameterNames || []) {
3666
3745
  parameterNames.add(jokerName);
3667
3746
  }