@promptbook/markdown-utils 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 +5 -3
- package/esm/index.es.js +51 -10
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/node.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/cli/cli-commands/common/handleActionErrors.d.ts +11 -0
- package/esm/typings/src/execution/ExecutionTask.d.ts +24 -0
- package/esm/typings/src/scrapers/_common/register/$provideScriptingForNode.d.ts +11 -0
- package/esm/typings/src/scripting/javascript/JavascriptEvalExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/JavascriptExecutionTools.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/postprocessing-functions.d.ts +1 -1
- package/esm/typings/src/scripting/javascript/utils/extractVariablesFromJavascript.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +50 -9
- package/umd/index.umd.js.map +1 -1
- /package/esm/typings/src/_packages/{execute-javascript.index.d.ts → javascript.index.d.ts} +0 -0
|
@@ -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 };
|
|
@@ -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/
|
|
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/
|
|
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/
|
|
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/
|
|
9
|
+
* @public exported from `@promptbook/javascript`
|
|
10
10
|
*/
|
|
11
11
|
export declare function extractVariablesFromJavascript(script: string_javascript): Set<string_javascript_name>;
|
|
12
12
|
/**
|
package/package.json
CHANGED
package/umd/index.umd.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @generated
|
|
26
26
|
* @see https://github.com/webgptorg/promptbook
|
|
27
27
|
*/
|
|
28
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
|
|
29
29
|
/**
|
|
30
30
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
31
31
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1993,21 +1993,41 @@
|
|
|
1993
1993
|
function createTask(options) {
|
|
1994
1994
|
const { taskType, taskProcessCallback } = options;
|
|
1995
1995
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
1996
|
-
|
|
1996
|
+
let status = 'RUNNING';
|
|
1997
|
+
const createdAt = new Date();
|
|
1998
|
+
let updatedAt = createdAt;
|
|
1999
|
+
const errors = [];
|
|
2000
|
+
const warnings = [];
|
|
2001
|
+
const currentValue = {};
|
|
2002
|
+
const partialResultSubject = new rxjs.Subject();
|
|
2003
|
+
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
1997
2004
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
2005
|
+
Object.assign(currentValue, newOngoingResult);
|
|
1998
2006
|
partialResultSubject.next(newOngoingResult);
|
|
1999
2007
|
});
|
|
2000
2008
|
finalResultPromise
|
|
2001
2009
|
.catch((error) => {
|
|
2010
|
+
errors.push(error);
|
|
2002
2011
|
partialResultSubject.error(error);
|
|
2003
2012
|
})
|
|
2004
|
-
.then((
|
|
2005
|
-
if (
|
|
2013
|
+
.then((executionResult) => {
|
|
2014
|
+
if (executionResult) {
|
|
2006
2015
|
try {
|
|
2007
|
-
|
|
2008
|
-
|
|
2016
|
+
updatedAt = new Date();
|
|
2017
|
+
errors.push(...executionResult.errors);
|
|
2018
|
+
warnings.push(...executionResult.warnings);
|
|
2019
|
+
// <- TODO: !!! Only unique errors and warnings should be added (or filtered)
|
|
2020
|
+
// TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2021
|
+
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2022
|
+
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2023
|
+
assertsTaskSuccessful(executionResult);
|
|
2024
|
+
status = 'FINISHED';
|
|
2025
|
+
Object.assign(currentValue, executionResult);
|
|
2026
|
+
partialResultSubject.next(executionResult);
|
|
2009
2027
|
}
|
|
2010
2028
|
catch (error) {
|
|
2029
|
+
status = 'ERROR';
|
|
2030
|
+
errors.push(error);
|
|
2011
2031
|
partialResultSubject.error(error);
|
|
2012
2032
|
}
|
|
2013
2033
|
}
|
|
@@ -2024,12 +2044,33 @@
|
|
|
2024
2044
|
return {
|
|
2025
2045
|
taskType,
|
|
2026
2046
|
taskId,
|
|
2047
|
+
get status() {
|
|
2048
|
+
return status;
|
|
2049
|
+
// <- Note: [1] Theese must be getters to allow changing the value in the future
|
|
2050
|
+
},
|
|
2051
|
+
get createdAt() {
|
|
2052
|
+
return createdAt;
|
|
2053
|
+
// <- Note: [1]
|
|
2054
|
+
},
|
|
2055
|
+
get updatedAt() {
|
|
2056
|
+
return updatedAt;
|
|
2057
|
+
// <- Note: [1]
|
|
2058
|
+
},
|
|
2027
2059
|
asPromise,
|
|
2028
2060
|
asObservable() {
|
|
2029
2061
|
return partialResultSubject.asObservable();
|
|
2030
2062
|
},
|
|
2063
|
+
get errors() {
|
|
2064
|
+
return errors;
|
|
2065
|
+
// <- Note: [1]
|
|
2066
|
+
},
|
|
2067
|
+
get warnings() {
|
|
2068
|
+
return warnings;
|
|
2069
|
+
// <- Note: [1]
|
|
2070
|
+
},
|
|
2031
2071
|
get currentValue() {
|
|
2032
|
-
return
|
|
2072
|
+
return currentValue;
|
|
2073
|
+
// <- Note: [1]
|
|
2033
2074
|
},
|
|
2034
2075
|
};
|
|
2035
2076
|
}
|
|
@@ -3726,7 +3767,7 @@
|
|
|
3726
3767
|
* @param script from which to extract the variables
|
|
3727
3768
|
* @returns the list of variable names
|
|
3728
3769
|
* @throws {ParseError} if the script is invalid
|
|
3729
|
-
* @public exported from `@promptbook/
|
|
3770
|
+
* @public exported from `@promptbook/javascript`
|
|
3730
3771
|
*/
|
|
3731
3772
|
function extractVariablesFromJavascript(script) {
|
|
3732
3773
|
const variables = new Set();
|
|
@@ -4688,7 +4729,7 @@
|
|
|
4688
4729
|
Last result:
|
|
4689
4730
|
${block($ongoingTaskResult.$resultString === null
|
|
4690
4731
|
? 'null'
|
|
4691
|
-
: $ongoingTaskResult.$resultString
|
|
4732
|
+
: spaceTrim.spaceTrim($ongoingTaskResult.$resultString)
|
|
4692
4733
|
.split('\n')
|
|
4693
4734
|
.map((line) => `> ${line}`)
|
|
4694
4735
|
.join('\n'))}
|