@promptbook/website-crawler 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
@@ -7,7 +7,7 @@ import { mkdir, rm } from 'fs/promises';
7
7
  import { basename, join, dirname } from 'path';
8
8
  import { format } from 'prettier';
9
9
  import parserHtml from 'prettier/parser-html';
10
- import { BehaviorSubject } from 'rxjs';
10
+ import { Subject } from 'rxjs';
11
11
  import { randomBytes } from 'crypto';
12
12
  import { forTime } from 'waitasecond';
13
13
  import sha256 from 'crypto-js/sha256';
@@ -29,7 +29,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
29
29
  * @generated
30
30
  * @see https://github.com/webgptorg/promptbook
31
31
  */
32
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0-1';
32
+ const PROMPTBOOK_ENGINE_VERSION = '0.88.0-8';
33
33
  /**
34
34
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
35
35
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2422,21 +2422,41 @@ function assertsTaskSuccessful(executionResult) {
2422
2422
  function createTask(options) {
2423
2423
  const { taskType, taskProcessCallback } = options;
2424
2424
  const taskId = `${taskType.toLowerCase().substring(0, 4)}-${$randomToken(8 /* <- TODO: To global config + Use Base58 to avoid simmilar char conflicts */)}`;
2425
- const partialResultSubject = new BehaviorSubject({});
2425
+ let status = 'RUNNING';
2426
+ const createdAt = new Date();
2427
+ let updatedAt = createdAt;
2428
+ const errors = [];
2429
+ const warnings = [];
2430
+ const currentValue = {};
2431
+ const partialResultSubject = new Subject();
2432
+ // <- Note: Not using `BehaviorSubject` because on error we can't access the last value
2426
2433
  const finalResultPromise = /* not await */ taskProcessCallback((newOngoingResult) => {
2434
+ Object.assign(currentValue, newOngoingResult);
2427
2435
  partialResultSubject.next(newOngoingResult);
2428
2436
  });
2429
2437
  finalResultPromise
2430
2438
  .catch((error) => {
2439
+ errors.push(error);
2431
2440
  partialResultSubject.error(error);
2432
2441
  })
2433
- .then((value) => {
2434
- if (value) {
2442
+ .then((executionResult) => {
2443
+ if (executionResult) {
2435
2444
  try {
2436
- assertsTaskSuccessful(value);
2437
- partialResultSubject.next(value);
2445
+ updatedAt = new Date();
2446
+ errors.push(...executionResult.errors);
2447
+ warnings.push(...executionResult.warnings);
2448
+ // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2449
+ // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2450
+ // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2451
+ // And delete `ExecutionTask.currentValue.preparedPipeline`
2452
+ assertsTaskSuccessful(executionResult);
2453
+ status = 'FINISHED';
2454
+ Object.assign(currentValue, executionResult);
2455
+ partialResultSubject.next(executionResult);
2438
2456
  }
2439
2457
  catch (error) {
2458
+ status = 'ERROR';
2459
+ errors.push(error);
2440
2460
  partialResultSubject.error(error);
2441
2461
  }
2442
2462
  }
@@ -2453,12 +2473,33 @@ function createTask(options) {
2453
2473
  return {
2454
2474
  taskType,
2455
2475
  taskId,
2476
+ get status() {
2477
+ return status;
2478
+ // <- Note: [1] Theese must be getters to allow changing the value in the future
2479
+ },
2480
+ get createdAt() {
2481
+ return createdAt;
2482
+ // <- Note: [1]
2483
+ },
2484
+ get updatedAt() {
2485
+ return updatedAt;
2486
+ // <- Note: [1]
2487
+ },
2456
2488
  asPromise,
2457
2489
  asObservable() {
2458
2490
  return partialResultSubject.asObservable();
2459
2491
  },
2492
+ get errors() {
2493
+ return errors;
2494
+ // <- Note: [1]
2495
+ },
2496
+ get warnings() {
2497
+ return warnings;
2498
+ // <- Note: [1]
2499
+ },
2460
2500
  get currentValue() {
2461
- return partialResultSubject.value;
2501
+ return currentValue;
2502
+ // <- Note: [1]
2462
2503
  },
2463
2504
  };
2464
2505
  }
@@ -4719,7 +4760,7 @@ async function executeAttempts(options) {
4719
4760
  Last result:
4720
4761
  ${block($ongoingTaskResult.$resultString === null
4721
4762
  ? 'null'
4722
- : $ongoingTaskResult.$resultString
4763
+ : spaceTrim($ongoingTaskResult.$resultString)
4723
4764
  .split('\n')
4724
4765
  .map((line) => `> ${line}`)
4725
4766
  .join('\n'))}