@promptbook/node 0.86.31 → 0.88.0-10

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.
@@ -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 };
@@ -40,6 +40,7 @@ import type { ExecutionReportString } from '../execution/execution-report/Execut
40
40
  import type { ExecutionReportStringOptions } from '../execution/execution-report/ExecutionReportStringOptions';
41
41
  import type { ExecutionTask } from '../execution/ExecutionTask';
42
42
  import type { PreparationTask } from '../execution/ExecutionTask';
43
+ import type { task_status } from '../execution/ExecutionTask';
43
44
  import type { AbstractTask } from '../execution/ExecutionTask';
44
45
  import type { Task } from '../execution/ExecutionTask';
45
46
  import type { ExecutionTools } from '../execution/ExecutionTools';
@@ -322,6 +323,7 @@ export type { ExecutionReportString };
322
323
  export type { ExecutionReportStringOptions };
323
324
  export type { ExecutionTask };
324
325
  export type { PreparationTask };
326
+ export type { task_status };
325
327
  export type { AbstractTask };
326
328
  export type { Task };
327
329
  export type { ExecutionTools };
@@ -62,6 +62,7 @@ import { clonePipeline } from '../utils/serialization/clonePipeline';
62
62
  import { deepClone } from '../utils/serialization/deepClone';
63
63
  import { exportJson } from '../utils/serialization/exportJson';
64
64
  import { isSerializableAsJson } from '../utils/serialization/isSerializableAsJson';
65
+ import { jsonStringsToJsons } from '../utils/serialization/jsonStringsToJsons';
65
66
  import { difference } from '../utils/sets/difference';
66
67
  import { intersection } from '../utils/sets/intersection';
67
68
  import { union } from '../utils/sets/union';
@@ -143,6 +144,7 @@ export { clonePipeline };
143
144
  export { deepClone };
144
145
  export { exportJson };
145
146
  export { isSerializableAsJson };
147
+ export { jsonStringsToJsons };
146
148
  export { difference };
147
149
  export { intersection };
148
150
  export { union };
@@ -0,0 +1,11 @@
1
+ import type { Command as Program } from 'commander';
2
+ type actionCallbackFunction = Parameters<Program['action']>[0];
3
+ /**
4
+ * Wraps action to handle error console logging and exit process with error code
5
+ *
6
+ * @param action Action to be wrapped in error handling
7
+ * @returns Wrapped action
8
+ * @private internal helper function for CLI commands
9
+ */
10
+ export declare function handleActionErrors(action: actionCallbackFunction): actionCallbackFunction;
11
+ export {};
@@ -40,6 +40,10 @@ export type PreparationTask = AbstractTask<PipelineExecutorResult> & {
40
40
  readonly taskType: 'PREPARATION';
41
41
  readonly taskId: `prep-${task_id}`;
42
42
  };
43
+ /**
44
+ * Status of a task
45
+ */
46
+ export type task_status = 'RUNNING' | 'FINISHED' | 'ERROR';
43
47
  /**
44
48
  * Base interface for all task types
45
49
  */
@@ -52,6 +56,18 @@ export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
52
56
  * Unique identifier for the task
53
57
  */
54
58
  readonly taskId: task_id;
59
+ /**
60
+ * Status of the task
61
+ */
62
+ readonly status: task_status;
63
+ /**
64
+ * Date when the task was created
65
+ */
66
+ readonly createdAt: Date;
67
+ /**
68
+ * Date when the task was last updated
69
+ */
70
+ readonly updatedAt: Date;
55
71
  /**
56
72
  * Gets a promise that resolves with the task result
57
73
  */
@@ -66,6 +82,14 @@ export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
66
82
  * Gets just the current value which is mutated during the task processing
67
83
  */
68
84
  currentValue: PartialDeep<TTaskResult>;
85
+ /**
86
+ * List of errors that occurred during the task processing
87
+ */
88
+ readonly errors: Array<Error>;
89
+ /**
90
+ * List of warnings that occurred during the task processing
91
+ */
92
+ readonly warnings: Array<Error>;
69
93
  };
70
94
  export type Task = ExecutionTask | PreparationTask;
71
95
  export {};
@@ -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/execute-javascript`
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/execute-javascript`
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/execute-javascript`
23
+ * @public exported from `@promptbook/javascript`
24
24
  */
25
25
  export declare const POSTPROCESSING_FUNCTIONS: {
26
26
  spaceTrim: typeof spaceTrim;
@@ -6,7 +6,7 @@ import type { string_javascript_name } from '../../../types/typeAliases';
6
6
  * @param script from which to extract the variables
7
7
  * @returns the list of variable names
8
8
  * @throws {ParseError} if the script is invalid
9
- * @public exported from `@promptbook/execute-javascript`
9
+ * @public exported from `@promptbook/javascript`
10
10
  */
11
11
  export declare function extractVariablesFromJavascript(script: string_javascript): Set<string_javascript_name>;
12
12
  /**
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Recursively converts JSON strings to JSON objects
3
+
4
+ * @public exported from `@promptbook/utils`
5
+ */
6
+ export declare function jsonStringsToJsons<T>(object: T): T;
7
+ /**
8
+ * TODO: Type the return type correctly
9
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/node",
3
- "version": "0.86.31",
3
+ "version": "0.88.0-10",
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/node.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.86.31"
50
+ "@promptbook/core": "0.88.0-10"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -46,7 +46,7 @@
46
46
  * @generated
47
47
  * @see https://github.com/webgptorg/promptbook
48
48
  */
49
- const PROMPTBOOK_ENGINE_VERSION = '0.86.31';
49
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0-10';
50
50
  /**
51
51
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
52
52
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1621,6 +1621,36 @@
1621
1621
  * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
1622
1622
  */
1623
1623
 
1624
+ /**
1625
+ * Recursively converts JSON strings to JSON objects
1626
+
1627
+ * @public exported from `@promptbook/utils`
1628
+ */
1629
+ function jsonStringsToJsons(object) {
1630
+ if (object === null) {
1631
+ return object;
1632
+ }
1633
+ if (Array.isArray(object)) {
1634
+ return object.map(jsonStringsToJsons);
1635
+ }
1636
+ if (typeof object !== 'object') {
1637
+ return object;
1638
+ }
1639
+ const newObject = { ...object };
1640
+ for (const [key, value] of Object.entries(object)) {
1641
+ if (typeof value === 'string' && isValidJsonString(value)) {
1642
+ newObject[key] = JSON.parse(value);
1643
+ }
1644
+ else {
1645
+ newObject[key] = jsonStringsToJsons(value);
1646
+ }
1647
+ }
1648
+ return newObject;
1649
+ }
1650
+ /**
1651
+ * TODO: Type the return type correctly
1652
+ */
1653
+
1624
1654
  /**
1625
1655
  * This error indicates errors during the execution of the pipeline
1626
1656
  *
@@ -1886,21 +1916,43 @@
1886
1916
  function createTask(options) {
1887
1917
  const { taskType, taskProcessCallback } = options;
1888
1918
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
1889
- const partialResultSubject = new rxjs.BehaviorSubject({});
1919
+ let status = 'RUNNING';
1920
+ const createdAt = new Date();
1921
+ let updatedAt = createdAt;
1922
+ const errors = [];
1923
+ const warnings = [];
1924
+ let currentValue = {};
1925
+ const partialResultSubject = new rxjs.Subject();
1926
+ // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
1890
1927
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
1928
+ Object.assign(currentValue, newOngoingResult);
1929
+ // <- TODO: assign deep
1891
1930
  partialResultSubject.next(newOngoingResult);
1892
1931
  });
1893
1932
  finalResultPromise
1894
1933
  .catch((error) => {
1934
+ errors.push(error);
1895
1935
  partialResultSubject.error(error);
1896
1936
  })
1897
- .then((value) => {
1898
- if (value) {
1937
+ .then((executionResult) => {
1938
+ if (executionResult) {
1899
1939
  try {
1900
- assertsTaskSuccessful(value);
1901
- partialResultSubject.next(value);
1940
+ updatedAt = new Date();
1941
+ errors.push(...executionResult.errors);
1942
+ warnings.push(...executionResult.warnings);
1943
+ // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
1944
+ // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
1945
+ // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
1946
+ // And delete `ExecutionTask.currentValue.preparedPipeline`
1947
+ assertsTaskSuccessful(executionResult);
1948
+ status = 'FINISHED';
1949
+ currentValue = jsonStringsToJsons(executionResult);
1950
+ // <- TODO: [🧠] Is this a good idea to convert JSON strins to JSONs?
1951
+ partialResultSubject.next(executionResult);
1902
1952
  }
1903
1953
  catch (error) {
1954
+ status = 'ERROR';
1955
+ errors.push(error);
1904
1956
  partialResultSubject.error(error);
1905
1957
  }
1906
1958
  }
@@ -1917,12 +1969,33 @@
1917
1969
  return {
1918
1970
  taskType,
1919
1971
  taskId,
1972
+ get status() {
1973
+ return status;
1974
+ // <- Note: [1] Theese must be getters to allow changing the value in the future
1975
+ },
1976
+ get createdAt() {
1977
+ return createdAt;
1978
+ // <- Note: [1]
1979
+ },
1980
+ get updatedAt() {
1981
+ return updatedAt;
1982
+ // <- Note: [1]
1983
+ },
1920
1984
  asPromise,
1921
1985
  asObservable() {
1922
1986
  return partialResultSubject.asObservable();
1923
1987
  },
1988
+ get errors() {
1989
+ return errors;
1990
+ // <- Note: [1]
1991
+ },
1992
+ get warnings() {
1993
+ return warnings;
1994
+ // <- Note: [1]
1995
+ },
1924
1996
  get currentValue() {
1925
- return partialResultSubject.value;
1997
+ return currentValue;
1998
+ // <- Note: [1]
1926
1999
  },
1927
2000
  };
1928
2001
  }
@@ -2138,7 +2211,7 @@
2138
2211
  * @param script from which to extract the variables
2139
2212
  * @returns the list of variable names
2140
2213
  * @throws {ParseError} if the script is invalid
2141
- * @public exported from `@promptbook/execute-javascript`
2214
+ * @public exported from `@promptbook/javascript`
2142
2215
  */
2143
2216
  function extractVariablesFromJavascript(script) {
2144
2217
  const variables = new Set();
@@ -3689,7 +3762,7 @@
3689
3762
  Last result:
3690
3763
  ${block($ongoingTaskResult.$resultString === null
3691
3764
  ? 'null'
3692
- : $ongoingTaskResult.$resultString
3765
+ : spaceTrim.spaceTrim($ongoingTaskResult.$resultString)
3693
3766
  .split('\n')
3694
3767
  .map((line) => `> ${line}`)
3695
3768
  .join('\n'))}
@@ -9921,7 +9994,7 @@
9921
9994
  * Warning: It is used for testing and mocking
9922
9995
  * **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
9923
9996
  *
9924
- * @public exported from `@promptbook/execute-javascript`
9997
+ * @public exported from `@promptbook/javascript`
9925
9998
  */
9926
9999
  class JavascriptEvalExecutionTools {
9927
10000
  constructor(options) {
@@ -10027,7 +10100,8 @@
10027
10100
  // Note: Custom functions are exposed to the current scope as variables
10028
10101
  `const ${functionName} = customFunctions.${functionName};`)
10029
10102
  .join('\n');
10030
- script = templateParameters(script, parameters);
10103
+ // script = templateParameters(script, parameters);
10104
+ // <- TODO: [🧠][🥳] Should be this is one of two variants how to use parameters in script
10031
10105
  const statementToEvaluate = spaceTrim__default["default"]((block) => `
10032
10106
 
10033
10107
  // Build-in functions:
@@ -10118,7 +10192,7 @@
10118
10192
  * Placeholder for better implementation of JavascriptExecutionTools - some propper sandboxing
10119
10193
  *
10120
10194
  * @alias JavascriptExecutionTools
10121
- * @public exported from `@promptbook/execute-javascript`
10195
+ * @public exported from `@promptbook/javascript`
10122
10196
  */
10123
10197
  const JavascriptExecutionTools = JavascriptEvalExecutionTools;
10124
10198
 
@@ -10461,6 +10535,22 @@
10461
10535
  * TODO: Maybe move from `@promptbook/node` to `@promptbook/core` as we removes direct dependency on `fs`
10462
10536
  */
10463
10537
 
10538
+ /**
10539
+ * Provides script execution tools
10540
+ *
10541
+ * @public exported from `@promptbook/node`
10542
+ */
10543
+ async function $provideScriptingForNode(options) {
10544
+ if (!$isRunningInNode()) {
10545
+ throw new EnvironmentMismatchError('Function `$provideScriptingForNode` works only in Node.js environment');
10546
+ }
10547
+ // TODO: [🔱] Do here auto-installation
10548
+ return [new JavascriptExecutionTools(options)];
10549
+ }
10550
+ /**
10551
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
10552
+ */
10553
+
10464
10554
  /**
10465
10555
  * Stringify the PipelineJson with proper formatting
10466
10556
  *
@@ -10587,6 +10677,7 @@
10587
10677
  exports.$provideLlmToolsConfigurationFromEnv = $provideLlmToolsConfigurationFromEnv;
10588
10678
  exports.$provideLlmToolsFromEnv = $provideLlmToolsFromEnv;
10589
10679
  exports.$provideScrapersForNode = $provideScrapersForNode;
10680
+ exports.$provideScriptingForNode = $provideScriptingForNode;
10590
10681
  exports.BOOK_LANGUAGE_VERSION = BOOK_LANGUAGE_VERSION;
10591
10682
  exports.FileCacheStorage = FileCacheStorage;
10592
10683
  exports.PROMPTBOOK_ENGINE_VERSION = PROMPTBOOK_ENGINE_VERSION;