@promptbook/pdf 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/pdf`
27
31
 
28
32
  - Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -251,7 +255,7 @@ Or you can install them separately:
251
255
  - ⭐ **[@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
252
256
  - **[@promptbook/markdown-utils](https://www.npmjs.com/package/@promptbook/markdown-utils)** - Utility functions used for processing markdown
253
257
  - _(Not finished)_ **[@promptbook/wizzard](https://www.npmjs.com/package/@promptbook/wizzard)** - Wizard for creating+running promptbooks in single line
254
- - **[@promptbook/execute-javascript](https://www.npmjs.com/package/@promptbook/execute-javascript)** - Execution tools for javascript inside promptbooks
258
+ - **[@promptbook/javascript](https://www.npmjs.com/package/@promptbook/javascript)** - Execution tools for javascript inside promptbooks
255
259
  - **[@promptbook/openai](https://www.npmjs.com/package/@promptbook/openai)** - Execution tools for OpenAI API, wrapper around OpenAI SDK
256
260
  - **[@promptbook/anthropic-claude](https://www.npmjs.com/package/@promptbook/anthropic-claude)** - Execution tools for Anthropic Claude API, wrapper around Anthropic Claude SDK
257
261
  - **[@promptbook/vercel](https://www.npmjs.com/package/@promptbook/vercel)** - Adapter for Vercel functionalities
@@ -407,8 +411,6 @@ Promptbook project is under [BUSL 1.1 is an SPDX license](https://spdx.org/licen
407
411
 
408
412
  See [TODO.md](./TODO.md)
409
413
 
410
-
411
-
412
414
  ## 🤝 Partners
413
415
 
414
416
  <div style="display: flex; align-items: center; gap: 20px;">
package/esm/index.es.js CHANGED
@@ -5,7 +5,7 @@ import hexEncoder from 'crypto-js/enc-hex';
5
5
  import { basename, join, dirname } from 'path';
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 sha256 from 'crypto-js/sha256';
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.86.31';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2307,21 +2307,41 @@ function assertsTaskSuccessful(executionResult) {
2307
2307
  function createTask(options) {
2308
2308
  const { taskType, taskProcessCallback } = options;
2309
2309
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2310
- const partialResultSubject = new BehaviorSubject({});
2310
+ let status = 'RUNNING';
2311
+ const createdAt = new Date();
2312
+ let updatedAt = createdAt;
2313
+ const errors = [];
2314
+ const warnings = [];
2315
+ const currentValue = {};
2316
+ const partialResultSubject = new Subject();
2317
+ // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2311
2318
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2319
+ Object.assign(currentValue, newOngoingResult);
2312
2320
  partialResultSubject.next(newOngoingResult);
2313
2321
  });
2314
2322
  finalResultPromise
2315
2323
  .catch((error) => {
2324
+ errors.push(error);
2316
2325
  partialResultSubject.error(error);
2317
2326
  })
2318
- .then((value) => {
2319
- if (value) {
2327
+ .then((executionResult) => {
2328
+ if (executionResult) {
2320
2329
  try {
2321
- assertsTaskSuccessful(value);
2322
- partialResultSubject.next(value);
2330
+ updatedAt = new Date();
2331
+ errors.push(...executionResult.errors);
2332
+ warnings.push(...executionResult.warnings);
2333
+ // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2334
+ // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2335
+ // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2336
+ // And delete `ExecutionTask.currentValue.preparedPipeline`
2337
+ assertsTaskSuccessful(executionResult);
2338
+ status = 'FINISHED';
2339
+ Object.assign(currentValue, executionResult);
2340
+ partialResultSubject.next(executionResult);
2323
2341
  }
2324
2342
  catch (error) {
2343
+ status = 'ERROR';
2344
+ errors.push(error);
2325
2345
  partialResultSubject.error(error);
2326
2346
  }
2327
2347
  }
@@ -2338,12 +2358,33 @@ function createTask(options) {
2338
2358
  return {
2339
2359
  taskType,
2340
2360
  taskId,
2361
+ get status() {
2362
+ return status;
2363
+ // <- Note: [1] Theese must be getters to allow changing the value in the future
2364
+ },
2365
+ get createdAt() {
2366
+ return createdAt;
2367
+ // <- Note: [1]
2368
+ },
2369
+ get updatedAt() {
2370
+ return updatedAt;
2371
+ // <- Note: [1]
2372
+ },
2341
2373
  asPromise,
2342
2374
  asObservable() {
2343
2375
  return partialResultSubject.asObservable();
2344
2376
  },
2377
+ get errors() {
2378
+ return errors;
2379
+ // <- Note: [1]
2380
+ },
2381
+ get warnings() {
2382
+ return warnings;
2383
+ // <- Note: [1]
2384
+ },
2345
2385
  get currentValue() {
2346
- return partialResultSubject.value;
2386
+ return currentValue;
2387
+ // <- Note: [1]
2347
2388
  },
2348
2389
  };
2349
2390
  }
@@ -3654,7 +3695,7 @@ function valueToString(value) {
3654
3695
  * @param script from which to extract the variables
3655
3696
  * @returns the list of variable names
3656
3697
  * @throws {ParseError} if the script is invalid
3657
- * @public exported from `@promptbook/execute-javascript`
3698
+ * @public exported from `@promptbook/javascript`
3658
3699
  */
3659
3700
  function extractVariablesFromJavascript(script) {
3660
3701
  const variables = new Set();
@@ -4718,7 +4759,7 @@ async function executeAttempts(options) {
4718
4759
  Last result:
4719
4760
  ${block($ongoingTaskResult.$resultString === null
4720
4761
  ? 'null'
4721
- : $ongoingTaskResult.$resultString
4762
+ : spaceTrim$1($ongoingTaskResult.$resultString)
4722
4763
  .split('\n')
4723
4764
  .map((line) => `> ${line}`)
4724
4765
  .join('\n'))}