@promptbook/node 0.88.0-1 → 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/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.88.0-1';
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
  }
@@ -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'))}