@promptbook/documents 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 +2 -2
- 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
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/documents`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -252,7 +256,7 @@ Or you can install them separately:
|
|
|
252
256
|
- ⭐ **[@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
|
|
253
257
|
- **[@promptbook/markdown-utils](https://www.npmjs.com/package/@promptbook/markdown-utils)** - Utility functions used for processing markdown
|
|
254
258
|
- _(Not finished)_ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizard for creating+running promptbooks in single line
|
|
255
|
-
- **[@promptbook/
|
|
259
|
+
- **[@promptbook/javascript](https://www.npmjs.com/package/@promptbook/javascript)** - Execution tools for javascript inside promptbooks
|
|
256
260
|
- **[@promptbook/openai](https://www.npmjs.com/package/@promptbook/openai)** - Execution tools for OpenAI API, wrapper around OpenAI SDK
|
|
257
261
|
- **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
|
|
258
262
|
- **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
|
|
@@ -408,8 +412,6 @@ Promptbook project is under [BUSL 1.1 is an SPDX license](https://spdx.org/licen
|
|
|
408
412
|
|
|
409
413
|
See [TODO.md](./TODO.md)
|
|
410
414
|
|
|
411
|
-
|
|
412
|
-
|
|
413
415
|
## 🤝 Partners
|
|
414
416
|
|
|
415
417
|
<div style="display: flex; align-items: center; gap: 20px;">
|
package/esm/index.es.js
CHANGED
|
@@ -8,7 +8,7 @@ import hexEncoder from 'crypto-js/enc-hex';
|
|
|
8
8
|
import { basename, join, dirname } from 'path';
|
|
9
9
|
import { format } from 'prettier';
|
|
10
10
|
import parserHtml from 'prettier/parser-html';
|
|
11
|
-
import {
|
|
11
|
+
import { Subject } from 'rxjs';
|
|
12
12
|
import { randomBytes } from 'crypto';
|
|
13
13
|
import sha256 from 'crypto-js/sha256';
|
|
14
14
|
import { lookup, extension } from 'mime-types';
|
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -2464,21 +2464,41 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2464
2464
|
function createTask(options) {
|
|
2465
2465
|
const { taskType, taskProcessCallback } = options;
|
|
2466
2466
|
const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
|
|
2467
|
-
|
|
2467
|
+
let status = 'RUNNING';
|
|
2468
|
+
const createdAt = new Date();
|
|
2469
|
+
let updatedAt = createdAt;
|
|
2470
|
+
const errors = [];
|
|
2471
|
+
const warnings = [];
|
|
2472
|
+
const currentValue = {};
|
|
2473
|
+
const partialResultSubject = new Subject();
|
|
2474
|
+
// <- Note: Not using `BehaviorSubject` because on error we can't access the last value
|
|
2468
2475
|
const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
|
|
2476
|
+
Object.assign(currentValue, newOngoingResult);
|
|
2469
2477
|
partialResultSubject.next(newOngoingResult);
|
|
2470
2478
|
});
|
|
2471
2479
|
finalResultPromise
|
|
2472
2480
|
.catch((error) => {
|
|
2481
|
+
errors.push(error);
|
|
2473
2482
|
partialResultSubject.error(error);
|
|
2474
2483
|
})
|
|
2475
|
-
.then((
|
|
2476
|
-
if (
|
|
2484
|
+
.then((executionResult) => {
|
|
2485
|
+
if (executionResult) {
|
|
2477
2486
|
try {
|
|
2478
|
-
|
|
2479
|
-
|
|
2487
|
+
updatedAt = new Date();
|
|
2488
|
+
errors.push(...executionResult.errors);
|
|
2489
|
+
warnings.push(...executionResult.warnings);
|
|
2490
|
+
// <- TODO: !!! Only unique errors and warnings should be added (or filtered)
|
|
2491
|
+
// TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2492
|
+
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2493
|
+
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2494
|
+
assertsTaskSuccessful(executionResult);
|
|
2495
|
+
status = 'FINISHED';
|
|
2496
|
+
Object.assign(currentValue, executionResult);
|
|
2497
|
+
partialResultSubject.next(executionResult);
|
|
2480
2498
|
}
|
|
2481
2499
|
catch (error) {
|
|
2500
|
+
status = 'ERROR';
|
|
2501
|
+
errors.push(error);
|
|
2482
2502
|
partialResultSubject.error(error);
|
|
2483
2503
|
}
|
|
2484
2504
|
}
|
|
@@ -2495,12 +2515,33 @@ function createTask(options) {
|
|
|
2495
2515
|
return {
|
|
2496
2516
|
taskType,
|
|
2497
2517
|
taskId,
|
|
2518
|
+
get status() {
|
|
2519
|
+
return status;
|
|
2520
|
+
// <- Note: [1] Theese must be getters to allow changing the value in the future
|
|
2521
|
+
},
|
|
2522
|
+
get createdAt() {
|
|
2523
|
+
return createdAt;
|
|
2524
|
+
// <- Note: [1]
|
|
2525
|
+
},
|
|
2526
|
+
get updatedAt() {
|
|
2527
|
+
return updatedAt;
|
|
2528
|
+
// <- Note: [1]
|
|
2529
|
+
},
|
|
2498
2530
|
asPromise,
|
|
2499
2531
|
asObservable() {
|
|
2500
2532
|
return partialResultSubject.asObservable();
|
|
2501
2533
|
},
|
|
2534
|
+
get errors() {
|
|
2535
|
+
return errors;
|
|
2536
|
+
// <- Note: [1]
|
|
2537
|
+
},
|
|
2538
|
+
get warnings() {
|
|
2539
|
+
return warnings;
|
|
2540
|
+
// <- Note: [1]
|
|
2541
|
+
},
|
|
2502
2542
|
get currentValue() {
|
|
2503
|
-
return
|
|
2543
|
+
return currentValue;
|
|
2544
|
+
// <- Note: [1]
|
|
2504
2545
|
},
|
|
2505
2546
|
};
|
|
2506
2547
|
}
|
|
@@ -3801,7 +3842,7 @@ function valueToString(value) {
|
|
|
3801
3842
|
* @param script from which to extract the variables
|
|
3802
3843
|
* @returns the list of variable names
|
|
3803
3844
|
* @throws {ParseError} if the script is invalid
|
|
3804
|
-
* @public exported from `@promptbook/
|
|
3845
|
+
* @public exported from `@promptbook/javascript`
|
|
3805
3846
|
*/
|
|
3806
3847
|
function extractVariablesFromJavascript(script) {
|
|
3807
3848
|
const variables = new Set();
|
|
@@ -4865,7 +4906,7 @@ async function executeAttempts(options) {
|
|
|
4865
4906
|
Last result:
|
|
4866
4907
|
${block($ongoingTaskResult.$resultString === null
|
|
4867
4908
|
? 'null'
|
|
4868
|
-
: $ongoingTaskResult.$resultString
|
|
4909
|
+
: spaceTrim($ongoingTaskResult.$resultString)
|
|
4869
4910
|
.split('\n')
|
|
4870
4911
|
.map((line) => `> ${line}`)
|
|
4871
4912
|
.join('\n'))}
|