@promptbook/node 0.86.31 → 0.88.0-8

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/node`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -253,7 +257,7 @@ Or you can install them separately:
253
257
  - ⭐ **[@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
254
258
  - **[@promptbook/markdown-utils](https://www.npmjs.com/package/@promptbook/markdown-utils)** - Utility functions used for processing markdown
255
259
  - _(Not finished)_ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizard for creating+running promptbooks in single line
256
- - **[@promptbook/execute-javascript](https://www.npmjs.com/package/@promptbook/execute-javascript)** - Execution tools for javascript inside promptbooks
260
+ - **[@promptbook/javascript](https://www.npmjs.com/package/@promptbook/javascript)** - Execution tools for javascript inside promptbooks
257
261
  - **[@promptbook/openai](https://www.npmjs.com/package/@promptbook/openai)** - Execution tools for OpenAI API, wrapper around OpenAI SDK
258
262
  - **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
259
263
  - **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
@@ -409,8 +413,6 @@ Promptbook project is under [BUSL 1.1 is an SPDX license](https://spdx.org/licen
409
413
 
410
414
  See [TODO.md](./TODO.md)
411
415
 
412
-
413
-
414
416
  ## 🤝 Partners
415
417
 
416
418
  <div style="display: flex; align-items: center; gap: 20px;">
package/esm/index.es.js CHANGED
@@ -5,7 +5,7 @@ import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
5
5
  import JSZip from 'jszip';
6
6
  import { format } from 'prettier';
7
7
  import parserHtml from 'prettier/parser-html';
8
- import { BehaviorSubject } from 'rxjs';
8
+ import { Subject } from 'rxjs';
9
9
  import { randomBytes } from 'crypto';
10
10
  import { forTime } from 'waitasecond';
11
11
  import { parse, unparse } from 'papaparse';
@@ -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.31';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
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
@@ -1870,21 +1870,41 @@ function assertsTaskSuccessful(executionResult) {
1870
1870
  function createTask(options) {
1871
1871
  const { taskType, taskProcessCallback } = options;
1872
1872
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1873
- const partialResultSubject = new BehaviorSubject({});
1873
+ let status = 'RUNNING';
1874
+ const createdAt = new Date();
1875
+ let updatedAt = createdAt;
1876
+ const errors = [];
1877
+ const warnings = [];
1878
+ const currentValue = {};
1879
+ const partialResultSubject = new Subject();
1880
+ // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
1874
1881
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
1882
+ Object.assign(currentValue, newOngoingResult);
1875
1883
  partialResultSubject.next(newOngoingResult);
1876
1884
  });
1877
1885
  finalResultPromise
1878
1886
  .catch((error) => {
1887
+ errors.push(error);
1879
1888
  partialResultSubject.error(error);
1880
1889
  })
1881
- .then((value) => {
1882
- if (value) {
1890
+ .then((executionResult) => {
1891
+ if (executionResult) {
1883
1892
  try {
1884
- assertsTaskSuccessful(value);
1885
- partialResultSubject.next(value);
1893
+ updatedAt = new Date();
1894
+ errors.push(...executionResult.errors);
1895
+ warnings.push(...executionResult.warnings);
1896
+ // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
1897
+ // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
1898
+ // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
1899
+ // And delete `ExecutionTask.currentValue.preparedPipeline`
1900
+ assertsTaskSuccessful(executionResult);
1901
+ status = 'FINISHED';
1902
+ Object.assign(currentValue, executionResult);
1903
+ partialResultSubject.next(executionResult);
1886
1904
  }
1887
1905
  catch (error) {
1906
+ status = 'ERROR';
1907
+ errors.push(error);
1888
1908
  partialResultSubject.error(error);
1889
1909
  }
1890
1910
  }
@@ -1901,12 +1921,33 @@ function createTask(options) {
1901
1921
  return {
1902
1922
  taskType,
1903
1923
  taskId,
1924
+ get status() {
1925
+ return status;
1926
+ // <- Note: [1] Theese must be getters to allow changing the value in the future
1927
+ },
1928
+ get createdAt() {
1929
+ return createdAt;
1930
+ // <- Note: [1]
1931
+ },
1932
+ get updatedAt() {
1933
+ return updatedAt;
1934
+ // <- Note: [1]
1935
+ },
1904
1936
  asPromise,
1905
1937
  asObservable() {
1906
1938
  return partialResultSubject.asObservable();
1907
1939
  },
1940
+ get errors() {
1941
+ return errors;
1942
+ // <- Note: [1]
1943
+ },
1944
+ get warnings() {
1945
+ return warnings;
1946
+ // <- Note: [1]
1947
+ },
1908
1948
  get currentValue() {
1909
- return partialResultSubject.value;
1949
+ return currentValue;
1950
+ // <- Note: [1]
1910
1951
  },
1911
1952
  };
1912
1953
  }
@@ -2122,7 +2163,7 @@ function addUsage(...usageItems) {
2122
2163
  * @param script from which to extract the variables
2123
2164
  * @returns the list of variable names
2124
2165
  * @throws {ParseError} if the script is invalid
2125
- * @public exported from `@promptbook/execute-javascript`
2166
+ * @public exported from `@promptbook/javascript`
2126
2167
  */
2127
2168
  function extractVariablesFromJavascript(script) {
2128
2169
  const variables = new Set();
@@ -3673,7 +3714,7 @@ async function executeAttempts(options) {
3673
3714
  Last result:
3674
3715
  ${block($ongoingTaskResult.$resultString === null
3675
3716
  ? 'null'
3676
- : $ongoingTaskResult.$resultString
3717
+ : spaceTrim$1($ongoingTaskResult.$resultString)
3677
3718
  .split('\n')
3678
3719
  .map((line) => `> ${line}`)
3679
3720
  .join('\n'))}
@@ -9905,7 +9946,7 @@ function preserve(func) {
9905
9946
  * Warning: It is used for testing and mocking
9906
9947
  * **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
9907
9948
  *
9908
- * @public exported from `@promptbook/execute-javascript`
9949
+ * @public exported from `@promptbook/javascript`
9909
9950
  */
9910
9951
  class JavascriptEvalExecutionTools {
9911
9952
  constructor(options) {
@@ -10011,7 +10052,8 @@ class JavascriptEvalExecutionTools {
10011
10052
  // Note: Custom functions are exposed to the current scope as variables
10012
10053
  `const ${functionName} = customFunctions.${functionName};`)
10013
10054
  .join('\n');
10014
- script = templateParameters(script, parameters);
10055
+ // script = templateParameters(script, parameters);
10056
+ // <- TODO: [🧠][🥳] Should be this is one of two variants how to use parameters in script
10015
10057
  const statementToEvaluate = spaceTrim((block) => `
10016
10058
 
10017
10059
  // Build-in functions:
@@ -10102,7 +10144,7 @@ class JavascriptEvalExecutionTools {
10102
10144
  * Placeholder for better implementation of JavascriptExecutionTools - some propper sandboxing
10103
10145
  *
10104
10146
  * @alias JavascriptExecutionTools
10105
- * @public exported from `@promptbook/execute-javascript`
10147
+ * @public exported from `@promptbook/javascript`
10106
10148
  */
10107
10149
  const JavascriptExecutionTools = JavascriptEvalExecutionTools;
10108
10150
 
@@ -10445,6 +10487,22 @@ async function createCollectionFromDirectory(rootPath, tools, options) {
10445
10487
  * TODO: Maybe move from `@promptbook/node` to `@promptbook/core` as we removes direct dependency on `fs`
10446
10488
  */
10447
10489
 
10490
+ /**
10491
+ * Provides script execution tools
10492
+ *
10493
+ * @public exported from `@promptbook/node`
10494
+ */
10495
+ async function $provideScriptingForNode(options) {
10496
+ if (!$isRunningInNode()) {
10497
+ throw new EnvironmentMismatchError('Function `$provideScriptingForNode` works only in Node.js environment');
10498
+ }
10499
+ // TODO: [🔱] Do here auto-installation
10500
+ return [new JavascriptExecutionTools(options)];
10501
+ }
10502
+ /**
10503
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
10504
+ */
10505
+
10448
10506
  /**
10449
10507
  * Stringify the PipelineJson with proper formatting
10450
10508
  *
@@ -10563,5 +10621,5 @@ async function $execCommands({ commands, cwd, crashOnError, }) {
10563
10621
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
10564
10622
  */
10565
10623
 
10566
- export { $execCommand, $execCommands, $provideExecutablesForNode, $provideExecutionToolsForNode, $provideFilesystemForNode, $provideLlmToolsConfigurationFromEnv, $provideLlmToolsFromEnv, $provideScrapersForNode, BOOK_LANGUAGE_VERSION, FileCacheStorage, PROMPTBOOK_ENGINE_VERSION, createCollectionFromDirectory };
10624
+ export { $execCommand, $execCommands, $provideExecutablesForNode, $provideExecutionToolsForNode, $provideFilesystemForNode, $provideLlmToolsConfigurationFromEnv, $provideLlmToolsFromEnv, $provideScrapersForNode, $provideScriptingForNode, BOOK_LANGUAGE_VERSION, FileCacheStorage, PROMPTBOOK_ENGINE_VERSION, createCollectionFromDirectory };
10567
10625
  //# sourceMappingURL=index.es.js.map