@promptbook/remote-server 0.85.0-4 → 0.85.0-5

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
@@ -1,13 +1,13 @@
1
1
  import colors from 'colors';
2
2
  import express from 'express';
3
- import http from 'node:http';
3
+ import http from 'http';
4
4
  import { Server } from 'socket.io';
5
5
  import spaceTrim$1, { spaceTrim } from 'spacetrim';
6
- import { spawn } from 'node:child_process';
7
6
  import { forTime } from 'waitasecond';
8
- import { stat, access, constants, readFile, writeFile, readdir, mkdir } from 'node:fs/promises';
9
- import { join, basename, dirname } from 'node:path';
10
- import { BehaviorSubject, concat, from } from 'rxjs';
7
+ import { spawn } from 'child_process';
8
+ import { stat, access, constants, readFile, writeFile, readdir, mkdir } from 'fs/promises';
9
+ import { join, basename, dirname } from 'path';
10
+ import { BehaviorSubject } from 'rxjs';
11
11
  import { randomBytes } from 'crypto';
12
12
  import { format } from 'prettier';
13
13
  import parserHtml from 'prettier/parser-html';
@@ -31,7 +31,7 @@ var BOOK_LANGUAGE_VERSION = '1.0.0';
31
31
  * @generated
32
32
  * @see https://github.com/webgptorg/promptbook
33
33
  */
34
- var PROMPTBOOK_ENGINE_VERSION = '0.85.0-3';
34
+ var PROMPTBOOK_ENGINE_VERSION = '0.85.0-4';
35
35
  /**
36
36
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
37
37
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -2014,6 +2014,24 @@ function createTask(options) {
2014
2014
  var finalResultPromise = /* not await */ taskProcessCallback(function (newOngoingResult) {
2015
2015
  partialResultSubject.next(newOngoingResult);
2016
2016
  });
2017
+ finalResultPromise
2018
+ .catch(function (error) {
2019
+ // console.error('!!!!! Task failed:', error);
2020
+ partialResultSubject.error(error);
2021
+ })
2022
+ .then(function (value) {
2023
+ // console.error('!!!!! Task finished:', value);
2024
+ if (value) {
2025
+ try {
2026
+ assertsTaskSuccessful(value);
2027
+ partialResultSubject.next(value);
2028
+ }
2029
+ catch (error) {
2030
+ partialResultSubject.error(error);
2031
+ }
2032
+ }
2033
+ partialResultSubject.complete();
2034
+ });
2017
2035
  function asPromise(options) {
2018
2036
  return __awaiter(this, void 0, void 0, function () {
2019
2037
  var _a, isCrashedOnError, finalResult;
@@ -2024,7 +2042,9 @@ function createTask(options) {
2024
2042
  return [4 /*yield*/, finalResultPromise];
2025
2043
  case 1:
2026
2044
  finalResult = _b.sent();
2045
+ console.error('!!!!! finalResult:', finalResult);
2027
2046
  if (isCrashedOnError) {
2047
+ console.error('!!!!! isCrashedOnError:', finalResult);
2028
2048
  assertsTaskSuccessful(finalResult);
2029
2049
  }
2030
2050
  return [2 /*return*/, finalResult];
@@ -2037,9 +2057,7 @@ function createTask(options) {
2037
2057
  taskId: taskId,
2038
2058
  asPromise: asPromise,
2039
2059
  asObservable: function () {
2040
- return concat(partialResultSubject.asObservable(), from(asPromise({
2041
- isCrashedOnError: true,
2042
- })));
2060
+ return partialResultSubject.asObservable();
2043
2061
  },
2044
2062
  get currentValue() {
2045
2063
  return partialResultSubject.value;
@@ -6886,7 +6904,7 @@ function startRemoteServer(options) {
6886
6904
  next();
6887
6905
  });
6888
6906
  var runningExecutionTasks = [];
6889
- // TODO: !!!!!! Do here some garbage collection of finished tasks
6907
+ // TODO: [🧠] Do here some garbage collection of finished tasks
6890
6908
  app.get(['/', rootPath], function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6891
6909
  var _a, _b;
6892
6910
  var _this = this;
@@ -6935,20 +6953,19 @@ function startRemoteServer(options) {
6935
6953
  });
6936
6954
  }); });
6937
6955
  app.get("".concat(rootPath, "/books"), function (request, response) { return __awaiter(_this, void 0, void 0, function () {
6938
- var _a, _b, _c;
6939
- return __generator(this, function (_d) {
6940
- switch (_d.label) {
6956
+ var pipelines;
6957
+ return __generator(this, function (_a) {
6958
+ switch (_a.label) {
6941
6959
  case 0:
6942
- _b = (_a = response).send;
6943
- if (!(collection === null)) return [3 /*break*/, 1];
6944
- _c = [];
6945
- return [3 /*break*/, 3];
6946
- case 1: return [4 /*yield*/, collection.listPipelines()];
6947
- case 2:
6948
- _c = _d.sent();
6949
- _d.label = 3;
6950
- case 3:
6951
- _b.apply(_a, [_c]);
6960
+ if (collection === null) {
6961
+ response.status(500).send('No collection available');
6962
+ return [2 /*return*/];
6963
+ }
6964
+ return [4 /*yield*/, collection.listPipelines()];
6965
+ case 1:
6966
+ pipelines = _a.sent();
6967
+ // <- TODO: [🧠][👩🏾‍🤝‍🧑🏿] List `inputParameters` required for the execution
6968
+ response.send(pipelines);
6952
6969
  return [2 /*return*/];
6953
6970
  }
6954
6971
  });
@@ -6978,13 +6995,12 @@ function startRemoteServer(options) {
6978
6995
  return __generator(this, function (_b) {
6979
6996
  switch (_b.label) {
6980
6997
  case 0:
6981
- _b.trys.push([0, 5, , 6]);
6998
+ _b.trys.push([0, 6, , 7]);
6982
6999
  inputParameters = request.body.inputParameters;
6983
7000
  pipelineUrl = request.body.pipelineUrl || request.body.book;
6984
7001
  return [4 /*yield*/, (collection === null || collection === void 0 ? void 0 : collection.getPipelineByUrl(pipelineUrl))];
6985
7002
  case 1:
6986
7003
  pipeline = _b.sent();
6987
- // <- TODO: !!!!!! NotFoundError
6988
7004
  if (pipeline === undefined) {
6989
7005
  response.status(404).send("Pipeline \"".concat(pipelineUrl, "\" not found"));
6990
7006
  return [2 /*return*/];
@@ -7011,20 +7027,21 @@ function startRemoteServer(options) {
7011
7027
  pipelineExecutor = createPipelineExecutor(__assign({ pipeline: pipeline, tools: tools }, options));
7012
7028
  executionTask = pipelineExecutor(inputParameters);
7013
7029
  runningExecutionTasks.push(executionTask);
7014
- response.send(executionTask);
7015
- // TODO: !!!!!! Remove this:
7016
- executionTask.asObservable().subscribe(function (_) {
7017
- console.log('!!!', _);
7018
- });
7019
- return [3 /*break*/, 6];
7030
+ return [4 /*yield*/, forTime(10)];
7020
7031
  case 5:
7032
+ _b.sent();
7033
+ // <- Note: Wait for a while to wait for quick responses or sudden but asynchronous errors
7034
+ // <- TODO: Put this into configuration
7035
+ response.send(executionTask);
7036
+ return [3 /*break*/, 7];
7037
+ case 6:
7021
7038
  error_1 = _b.sent();
7022
7039
  if (!(error_1 instanceof Error)) {
7023
7040
  throw error_1;
7024
7041
  }
7025
7042
  response.status(400).send({ error: serializeError(error_1) });
7026
- return [3 /*break*/, 6];
7027
- case 6: return [2 /*return*/];
7043
+ return [3 /*break*/, 7];
7044
+ case 7: return [2 /*return*/];
7028
7045
  }
7029
7046
  });
7030
7047
  }); });