@promptbook/remote-client 0.82.0-0 → 0.82.0-3

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.
Files changed (35) hide show
  1. package/esm/index.es.js +390 -363
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  4. package/esm/typings/src/_packages/remote-client.index.d.ts +9 -3
  5. package/esm/typings/src/_packages/remote-server.index.d.ts +8 -2
  6. package/esm/typings/src/_packages/types.index.d.ts +16 -26
  7. package/esm/typings/src/collection/PipelineCollection.d.ts +2 -0
  8. package/esm/typings/src/config.d.ts +6 -0
  9. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +6 -3
  10. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +2 -2
  11. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +3 -7
  12. package/esm/typings/src/other/templates/getBookTemplates.d.ts +5 -3
  13. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +5 -2
  14. package/esm/typings/src/remote-server/createRemoteClient.d.ts +10 -0
  15. package/esm/typings/src/remote-server/{interfaces → socket-types/_common}/PromptbookServer_Error.d.ts +3 -3
  16. package/esm/typings/src/remote-server/socket-types/_common/PromptbookServer_Progress.d.ts +10 -0
  17. package/esm/typings/src/remote-server/socket-types/_subtypes/PromptbookServer_Identification.d.ts +49 -0
  18. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +17 -0
  19. package/esm/typings/src/remote-server/{interfaces → socket-types/listModels}/PromptbookServer_ListModels_Response.d.ts +4 -2
  20. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +17 -0
  21. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Response.d.ts +12 -0
  22. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +17 -0
  23. package/esm/typings/src/remote-server/{interfaces → socket-types/prompt}/PromptbookServer_Prompt_Response.d.ts +3 -3
  24. package/esm/typings/src/remote-server/startRemoteServer.d.ts +3 -2
  25. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +32 -0
  26. package/esm/typings/src/types/Arrayable.d.ts +1 -0
  27. package/esm/typings/src/types/NonEmptyArray.d.ts +8 -0
  28. package/package.json +2 -2
  29. package/umd/index.umd.js +393 -366
  30. package/umd/index.umd.js.map +1 -1
  31. package/esm/typings/src/remote-server/interfaces/PromptbookServer_ListModels_Request.d.ts +0 -38
  32. package/esm/typings/src/remote-server/interfaces/PromptbookServer_Prompt_Progress.d.ts +0 -12
  33. package/esm/typings/src/remote-server/interfaces/PromptbookServer_Prompt_Request.d.ts +0 -45
  34. package/esm/typings/src/remote-server/interfaces/RemoteLlmExecutionToolsOptions.d.ts +0 -54
  35. /package/esm/typings/src/remote-server/{interfaces → types}/RemoteServerOptions.d.ts +0 -0
package/umd/index.umd.js CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('crypto-js'), require('crypto-js/enc-hex'), require('papaparse'), require('path'), require('socket.io-client')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'crypto-js', 'crypto-js/enc-hex', 'papaparse', 'path', 'socket.io-client'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-client"] = {}, global.spaceTrim, global.cryptoJs, global.hexEncoder, global.papaparse, global.path, global.socket_ioClient));
5
- })(this, (function (exports, spaceTrim, cryptoJs, hexEncoder, papaparse, path, socket_ioClient) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('spacetrim'), require('socket.io-client'), require('crypto-js'), require('crypto-js/enc-hex'), require('papaparse'), require('path')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'spacetrim', 'socket.io-client', 'crypto-js', 'crypto-js/enc-hex', 'papaparse', 'path'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["promptbook-remote-client"] = {}, global.spaceTrim, global.socket_ioClient, global.cryptoJs, global.hexEncoder, global.papaparse, global.path));
5
+ })(this, (function (exports, spaceTrim, socket_ioClient, cryptoJs, hexEncoder, papaparse, path) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -23,7 +23,7 @@
23
23
  * @generated
24
24
  * @see https://github.com/webgptorg/promptbook
25
25
  */
26
- var PROMPTBOOK_ENGINE_VERSION = '0.81.0-23';
26
+ var PROMPTBOOK_ENGINE_VERSION = '0.82.0-2';
27
27
  /**
28
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
29
29
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -149,24 +149,155 @@
149
149
  }
150
150
 
151
151
  /**
152
- * Prepare pipeline on remote server
152
+ * This error indicates problems parsing the format value
153
153
  *
154
- * @see https://github.com/webgptorg/promptbook/discussions/196
154
+ * For example, when the format value is not a valid JSON or CSV
155
+ * This is not thrown directly but in extended classes
155
156
  *
156
- * Note: This function does not validate logic of the pipeline
157
- * Note: This function acts as part of compilation process
158
- * Note: When the pipeline is already prepared, it returns the same pipeline
157
+ * @public exported from `@promptbook/core`
158
+ */
159
+ var AbstractFormatError = /** @class */ (function (_super) {
160
+ __extends(AbstractFormatError, _super);
161
+ // Note: To allow instanceof do not put here error `name`
162
+ // public readonly name = 'AbstractFormatError';
163
+ function AbstractFormatError(message) {
164
+ var _this = _super.call(this, message) || this;
165
+ Object.setPrototypeOf(_this, AbstractFormatError.prototype);
166
+ return _this;
167
+ }
168
+ return AbstractFormatError;
169
+ }(Error));
170
+
171
+ /**
172
+ * This error indicates problem with parsing of CSV
159
173
  *
160
- * @public exported from `@promptbook/remote-client`
174
+ * @public exported from `@promptbook/core`
161
175
  */
162
- function preparePipelineOnRemoteServer(pipeline, options) {
163
- return __awaiter(this, void 0, void 0, function () {
164
- return __generator(this, function (_a) {
165
- // TODO: !!!!!! do $exportJson
166
- return [2 /*return*/, pipeline];
167
- });
168
- });
169
- }
176
+ var CsvFormatError = /** @class */ (function (_super) {
177
+ __extends(CsvFormatError, _super);
178
+ function CsvFormatError(message) {
179
+ var _this = _super.call(this, message) || this;
180
+ _this.name = 'CsvFormatError';
181
+ Object.setPrototypeOf(_this, CsvFormatError.prototype);
182
+ return _this;
183
+ }
184
+ return CsvFormatError;
185
+ }(AbstractFormatError));
186
+
187
+ /**
188
+ * This error indicates that the pipeline collection cannot be propperly loaded
189
+ *
190
+ * @public exported from `@promptbook/core`
191
+ */
192
+ var CollectionError = /** @class */ (function (_super) {
193
+ __extends(CollectionError, _super);
194
+ function CollectionError(message) {
195
+ var _this = _super.call(this, message) || this;
196
+ _this.name = 'CollectionError';
197
+ Object.setPrototypeOf(_this, CollectionError.prototype);
198
+ return _this;
199
+ }
200
+ return CollectionError;
201
+ }(Error));
202
+
203
+ /**
204
+ * This error type indicates that you try to use a feature that is not available in the current environment
205
+ *
206
+ * @public exported from `@promptbook/core`
207
+ */
208
+ var EnvironmentMismatchError = /** @class */ (function (_super) {
209
+ __extends(EnvironmentMismatchError, _super);
210
+ function EnvironmentMismatchError(message) {
211
+ var _this = _super.call(this, message) || this;
212
+ _this.name = 'EnvironmentMismatchError';
213
+ Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
214
+ return _this;
215
+ }
216
+ return EnvironmentMismatchError;
217
+ }(Error));
218
+
219
+ /**
220
+ * This error occurs when some expectation is not met in the execution of the pipeline
221
+ *
222
+ * @public exported from `@promptbook/core`
223
+ * Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
224
+ * Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
225
+ * Note: This is a kindof subtype of PipelineExecutionError
226
+ */
227
+ var ExpectError = /** @class */ (function (_super) {
228
+ __extends(ExpectError, _super);
229
+ function ExpectError(message) {
230
+ var _this = _super.call(this, message) || this;
231
+ _this.name = 'ExpectError';
232
+ Object.setPrototypeOf(_this, ExpectError.prototype);
233
+ return _this;
234
+ }
235
+ return ExpectError;
236
+ }(Error));
237
+
238
+ /**
239
+ * This error indicates that the promptbook can not retrieve knowledge from external sources
240
+ *
241
+ * @public exported from `@promptbook/core`
242
+ */
243
+ var KnowledgeScrapeError = /** @class */ (function (_super) {
244
+ __extends(KnowledgeScrapeError, _super);
245
+ function KnowledgeScrapeError(message) {
246
+ var _this = _super.call(this, message) || this;
247
+ _this.name = 'KnowledgeScrapeError';
248
+ Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
249
+ return _this;
250
+ }
251
+ return KnowledgeScrapeError;
252
+ }(Error));
253
+
254
+ /**
255
+ * This error type indicates that some limit was reached
256
+ *
257
+ * @public exported from `@promptbook/core`
258
+ */
259
+ var LimitReachedError = /** @class */ (function (_super) {
260
+ __extends(LimitReachedError, _super);
261
+ function LimitReachedError(message) {
262
+ var _this = _super.call(this, message) || this;
263
+ _this.name = 'LimitReachedError';
264
+ Object.setPrototypeOf(_this, LimitReachedError.prototype);
265
+ return _this;
266
+ }
267
+ return LimitReachedError;
268
+ }(Error));
269
+
270
+ /**
271
+ * This error type indicates that some tools are missing for pipeline execution or preparation
272
+ *
273
+ * @public exported from `@promptbook/core`
274
+ */
275
+ var MissingToolsError = /** @class */ (function (_super) {
276
+ __extends(MissingToolsError, _super);
277
+ function MissingToolsError(message) {
278
+ var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
279
+ _this.name = 'MissingToolsError';
280
+ Object.setPrototypeOf(_this, MissingToolsError.prototype);
281
+ return _this;
282
+ }
283
+ return MissingToolsError;
284
+ }(Error));
285
+
286
+ /**
287
+ * This error indicates that promptbook not found in the collection
288
+ *
289
+ * @public exported from `@promptbook/core`
290
+ */
291
+ var NotFoundError = /** @class */ (function (_super) {
292
+ __extends(NotFoundError, _super);
293
+ function NotFoundError(message) {
294
+ var _this = _super.call(this, message) || this;
295
+ _this.name = 'NotFoundError';
296
+ Object.setPrototypeOf(_this, NotFoundError.prototype);
297
+ return _this;
298
+ }
299
+ return NotFoundError;
300
+ }(Error));
170
301
 
171
302
  /**
172
303
  * This error type indicates that some part of the code is not implemented yet
@@ -203,6 +334,54 @@
203
334
  * TODO: Maybe split `ParseError` and `ApplyError`
204
335
  */
205
336
 
337
+ /**
338
+ * This error indicates errors during the execution of the pipeline
339
+ *
340
+ * @public exported from `@promptbook/core`
341
+ */
342
+ var PipelineExecutionError = /** @class */ (function (_super) {
343
+ __extends(PipelineExecutionError, _super);
344
+ function PipelineExecutionError(message) {
345
+ var _this = _super.call(this, message) || this;
346
+ _this.name = 'PipelineExecutionError';
347
+ Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
348
+ return _this;
349
+ }
350
+ return PipelineExecutionError;
351
+ }(Error));
352
+
353
+ /**
354
+ * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
355
+ *
356
+ * @public exported from `@promptbook/core`
357
+ */
358
+ var PipelineLogicError = /** @class */ (function (_super) {
359
+ __extends(PipelineLogicError, _super);
360
+ function PipelineLogicError(message) {
361
+ var _this = _super.call(this, message) || this;
362
+ _this.name = 'PipelineLogicError';
363
+ Object.setPrototypeOf(_this, PipelineLogicError.prototype);
364
+ return _this;
365
+ }
366
+ return PipelineLogicError;
367
+ }(Error));
368
+
369
+ /**
370
+ * This error indicates errors in referencing promptbooks between each other
371
+ *
372
+ * @public exported from `@promptbook/core`
373
+ */
374
+ var PipelineUrlError = /** @class */ (function (_super) {
375
+ __extends(PipelineUrlError, _super);
376
+ function PipelineUrlError(message) {
377
+ var _this = _super.call(this, message) || this;
378
+ _this.name = 'PipelineUrlError';
379
+ Object.setPrototypeOf(_this, PipelineUrlError.prototype);
380
+ return _this;
381
+ }
382
+ return PipelineUrlError;
383
+ }(Error));
384
+
206
385
  /**
207
386
  * Returns the same value that is passed as argument.
208
387
  * No side effects.
@@ -249,6 +428,12 @@
249
428
  * @public exported from `@promptbook/core`
250
429
  */
251
430
  var DEFAULT_BOOK_TITLE = "\u2728 Untitled Book";
431
+ /**
432
+ * When the title of task is not provided, the default title is used
433
+ *
434
+ * @public exported from `@promptbook/core`
435
+ */
436
+ var DEFAULT_TASK_TITLE = "Task";
252
437
  /**
253
438
  * Timeout for the connections in milliseconds
254
439
  *
@@ -313,6 +498,161 @@
313
498
  return UnexpectedError;
314
499
  }(Error));
315
500
 
501
+ /**
502
+ * Index of all custom errors
503
+ *
504
+ * @public exported from `@promptbook/core`
505
+ */
506
+ var PROMPTBOOK_ERRORS = {
507
+ AbstractFormatError: AbstractFormatError,
508
+ CsvFormatError: CsvFormatError,
509
+ CollectionError: CollectionError,
510
+ EnvironmentMismatchError: EnvironmentMismatchError,
511
+ ExpectError: ExpectError,
512
+ KnowledgeScrapeError: KnowledgeScrapeError,
513
+ LimitReachedError: LimitReachedError,
514
+ MissingToolsError: MissingToolsError,
515
+ NotFoundError: NotFoundError,
516
+ NotYetImplementedError: NotYetImplementedError,
517
+ ParseError: ParseError,
518
+ PipelineExecutionError: PipelineExecutionError,
519
+ PipelineLogicError: PipelineLogicError,
520
+ PipelineUrlError: PipelineUrlError,
521
+ UnexpectedError: UnexpectedError,
522
+ // TODO: [🪑]> VersionMismatchError,
523
+ };
524
+ /**
525
+ * Index of all javascript errors
526
+ *
527
+ * @private for internal usage
528
+ */
529
+ var COMMON_JAVASCRIPT_ERRORS = {
530
+ Error: Error,
531
+ EvalError: EvalError,
532
+ RangeError: RangeError,
533
+ ReferenceError: ReferenceError,
534
+ SyntaxError: SyntaxError,
535
+ TypeError: TypeError,
536
+ URIError: URIError,
537
+ AggregateError: AggregateError,
538
+ /*
539
+ Note: Not widely supported
540
+ > InternalError,
541
+ > ModuleError,
542
+ > HeapError,
543
+ > WebAssemblyCompileError,
544
+ > WebAssemblyRuntimeError,
545
+ */
546
+ };
547
+ /**
548
+ * Index of all errors
549
+ *
550
+ * @private for internal usage
551
+ */
552
+ var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
553
+ /**
554
+ * Note: [💞] Ignore a discrepancy between file name and entity name
555
+ */
556
+
557
+ /**
558
+ * Deserializes the error object
559
+ *
560
+ * @public exported from `@promptbook/utils`
561
+ */
562
+ function deserializeError(error) {
563
+ var name = error.name, stack = error.stack;
564
+ var message = error.message;
565
+ var ErrorClass = ALL_ERRORS[error.name];
566
+ if (ErrorClass === undefined) {
567
+ ErrorClass = Error;
568
+ message = "".concat(name, ": ").concat(message);
569
+ }
570
+ if (stack !== undefined && stack !== '') {
571
+ message = spaceTrim__default["default"](function (block) { return "\n ".concat(block(message), "\n\n Original stack trace:\n ").concat(block(stack || ''), "\n "); });
572
+ }
573
+ return new ErrorClass(message);
574
+ }
575
+
576
+ /**
577
+ * Creates a connection to the remote proxy server.
578
+ *
579
+ * Note: This function creates a connection to the remote server and returns a socket but responsibility of closing the connection is on the caller
580
+ *
581
+ * @private internal utility function
582
+ */
583
+ function createRemoteClient(options) {
584
+ return __awaiter(this, void 0, void 0, function () {
585
+ var remoteUrl, path;
586
+ return __generator(this, function (_a) {
587
+ remoteUrl = options.remoteUrl, path = options.path;
588
+ return [2 /*return*/, new Promise(function (resolve, reject) {
589
+ var socket = socket_ioClient.io(remoteUrl, {
590
+ retries: CONNECTION_RETRIES_LIMIT,
591
+ timeout: CONNECTION_TIMEOUT_MS,
592
+ path: path,
593
+ // path: `${this.remoteUrl.pathname}/socket.io`,
594
+ transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
595
+ });
596
+ // console.log('Connecting to', this.options.remoteUrl.href, { socket });
597
+ socket.on('connect', function () {
598
+ resolve(socket);
599
+ });
600
+ // TODO: [💩] Better timeout handling
601
+ setTimeout(function () {
602
+ reject(new Error("Timeout while connecting to ".concat(remoteUrl)));
603
+ }, CONNECTION_TIMEOUT_MS);
604
+ })];
605
+ });
606
+ });
607
+ }
608
+
609
+ /**
610
+ * Prepare pipeline on remote server
611
+ *
612
+ * @see https://github.com/webgptorg/promptbook/discussions/196
613
+ *
614
+ * Note: This function does not validate logic of the pipeline
615
+ * Note: This function acts as part of compilation process
616
+ * Note: When the pipeline is already prepared, it returns the same pipeline
617
+ *
618
+ * @public exported from `@promptbook/remote-client`
619
+ */
620
+ function preparePipelineOnRemoteServer(pipeline, options) {
621
+ return __awaiter(this, void 0, void 0, function () {
622
+ var socket, preparedPipeline;
623
+ return __generator(this, function (_a) {
624
+ switch (_a.label) {
625
+ case 0:
626
+ return [4 /*yield*/, createRemoteClient(options)];
627
+ case 1:
628
+ socket = _a.sent();
629
+ socket.emit('preparePipeline-request', {
630
+ identification: options.identification,
631
+ pipeline: pipeline,
632
+ } /* <- Note: [🤛] */);
633
+ return [4 /*yield*/, new Promise(function (resolve, reject) {
634
+ socket.on('preparePipeline-response', function (response) {
635
+ resolve(response.preparedPipeline);
636
+ socket.disconnect();
637
+ });
638
+ socket.on('error', function (error) {
639
+ reject(deserializeError(error));
640
+ socket.disconnect();
641
+ });
642
+ })];
643
+ case 2:
644
+ preparedPipeline = _a.sent();
645
+ socket.disconnect();
646
+ // TODO: !!!!!! do $exportJson
647
+ return [2 /*return*/, preparedPipeline];
648
+ }
649
+ });
650
+ });
651
+ }
652
+ /**
653
+ * TODO: !!!! Do not return Promise<PipelineJson> But PreparePipelineTask
654
+ */
655
+
316
656
  /**
317
657
  * All available task types
318
658
  *
@@ -1463,61 +1803,25 @@
1463
1803
  throw new ParseError("Already defined maximum ".concat($taskJson.expectations[unit].max, " ").concat(command.unit.toLowerCase(), ", now trying to redefine it to ").concat(command.amount));
1464
1804
  }
1465
1805
  $taskJson.expectations[unit].max = command.amount;
1466
- }
1467
- },
1468
- /**
1469
- * Converts the FORMAT command back to string
1470
- *
1471
- * Note: This is used in `pipelineJsonToString` utility
1472
- */
1473
- stringify: function (command) {
1474
- return "---"; // <- TODO: [🛋] Implement
1475
- },
1476
- /**
1477
- * Reads the FORMAT command from the `TaskJson`
1478
- *
1479
- * Note: This is used in `pipelineJsonToString` utility
1480
- */
1481
- takeFromTaskJson: function ($taskJson) {
1482
- throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
1483
- },
1484
- };
1485
-
1486
- /**
1487
- * This error indicates problems parsing the format value
1488
- *
1489
- * For example, when the format value is not a valid JSON or CSV
1490
- * This is not thrown directly but in extended classes
1491
- *
1492
- * @public exported from `@promptbook/core`
1493
- */
1494
- var AbstractFormatError = /** @class */ (function (_super) {
1495
- __extends(AbstractFormatError, _super);
1496
- // Note: To allow instanceof do not put here error `name`
1497
- // public readonly name = 'AbstractFormatError';
1498
- function AbstractFormatError(message) {
1499
- var _this = _super.call(this, message) || this;
1500
- Object.setPrototypeOf(_this, AbstractFormatError.prototype);
1501
- return _this;
1502
- }
1503
- return AbstractFormatError;
1504
- }(Error));
1505
-
1506
- /**
1507
- * This error indicates problem with parsing of CSV
1508
- *
1509
- * @public exported from `@promptbook/core`
1510
- */
1511
- var CsvFormatError = /** @class */ (function (_super) {
1512
- __extends(CsvFormatError, _super);
1513
- function CsvFormatError(message) {
1514
- var _this = _super.call(this, message) || this;
1515
- _this.name = 'CsvFormatError';
1516
- Object.setPrototypeOf(_this, CsvFormatError.prototype);
1517
- return _this;
1518
- }
1519
- return CsvFormatError;
1520
- }(AbstractFormatError));
1806
+ }
1807
+ },
1808
+ /**
1809
+ * Converts the FORMAT command back to string
1810
+ *
1811
+ * Note: This is used in `pipelineJsonToString` utility
1812
+ */
1813
+ stringify: function (command) {
1814
+ return "---"; // <- TODO: [🛋] Implement
1815
+ },
1816
+ /**
1817
+ * Reads the FORMAT command from the `TaskJson`
1818
+ *
1819
+ * Note: This is used in `pipelineJsonToString` utility
1820
+ */
1821
+ takeFromTaskJson: function ($taskJson) {
1822
+ throw new NotYetImplementedError("[\uD83D\uDECB] Not implemented yet"); // <- TODO: [🛋] Implement
1823
+ },
1824
+ };
1521
1825
 
1522
1826
  /**
1523
1827
  * @@@
@@ -4969,8 +5273,8 @@
4969
5273
  isSectionTypeSet: false,
4970
5274
  isTask: true,
4971
5275
  taskType: undefined /* <- Note: [🍙] Putting here placeholder to keep `taskType` on top at final JSON */,
4972
- name: getUniqueSectionName(section.title),
4973
- title: section.title,
5276
+ name: getUniqueSectionName(section.title || DEFAULT_TASK_TITLE),
5277
+ title: section.title || DEFAULT_TASK_TITLE,
4974
5278
  description: description_1,
4975
5279
  content: content,
4976
5280
  // <- TODO: [🍙] Some standard order of properties
@@ -5238,7 +5542,7 @@
5238
5542
  * Note: This function acts as compilation process
5239
5543
  *
5240
5544
  * @param pipelineString {Promptbook} in string markdown format (.book.md)
5241
- * @param options - Options for remote server compilation
5545
+ * @param options - Configuration of the remote server
5242
5546
  * @returns {Promptbook} compiled in JSON format (.book.json)
5243
5547
  * @throws {ParseError} if the promptbook string is not valid
5244
5548
  * @public exported from `@promptbook/remote-client`
@@ -5250,7 +5554,7 @@
5250
5554
  switch (_a.label) {
5251
5555
  case 0:
5252
5556
  pipelineJson = parsePipeline(pipelineString);
5253
- return [4 /*yield*/, preparePipelineOnRemoteServer(pipelineJson)];
5557
+ return [4 /*yield*/, preparePipelineOnRemoteServer(pipelineJson, options)];
5254
5558
  case 1:
5255
5559
  pipelineJson = _a.sent();
5256
5560
  // Note: No need to use `$exportJson` because `parsePipeline` and `preparePipeline` already do that
@@ -5259,238 +5563,9 @@
5259
5563
  });
5260
5564
  });
5261
5565
  }
5262
-
5263
- /**
5264
- * This error indicates that the pipeline collection cannot be propperly loaded
5265
- *
5266
- * @public exported from `@promptbook/core`
5267
- */
5268
- var CollectionError = /** @class */ (function (_super) {
5269
- __extends(CollectionError, _super);
5270
- function CollectionError(message) {
5271
- var _this = _super.call(this, message) || this;
5272
- _this.name = 'CollectionError';
5273
- Object.setPrototypeOf(_this, CollectionError.prototype);
5274
- return _this;
5275
- }
5276
- return CollectionError;
5277
- }(Error));
5278
-
5279
- /**
5280
- * This error type indicates that you try to use a feature that is not available in the current environment
5281
- *
5282
- * @public exported from `@promptbook/core`
5283
- */
5284
- var EnvironmentMismatchError = /** @class */ (function (_super) {
5285
- __extends(EnvironmentMismatchError, _super);
5286
- function EnvironmentMismatchError(message) {
5287
- var _this = _super.call(this, message) || this;
5288
- _this.name = 'EnvironmentMismatchError';
5289
- Object.setPrototypeOf(_this, EnvironmentMismatchError.prototype);
5290
- return _this;
5291
- }
5292
- return EnvironmentMismatchError;
5293
- }(Error));
5294
-
5295
- /**
5296
- * This error occurs when some expectation is not met in the execution of the pipeline
5297
- *
5298
- * @public exported from `@promptbook/core`
5299
- * Note: Do not throw this error, its reserved for `checkExpectations` and `createPipelineExecutor` and public ONLY to be serializable through remote server
5300
- * Note: Always thrown in `checkExpectations` and catched in `createPipelineExecutor` and rethrown as `PipelineExecutionError`
5301
- * Note: This is a kindof subtype of PipelineExecutionError
5302
- */
5303
- var ExpectError = /** @class */ (function (_super) {
5304
- __extends(ExpectError, _super);
5305
- function ExpectError(message) {
5306
- var _this = _super.call(this, message) || this;
5307
- _this.name = 'ExpectError';
5308
- Object.setPrototypeOf(_this, ExpectError.prototype);
5309
- return _this;
5310
- }
5311
- return ExpectError;
5312
- }(Error));
5313
-
5314
- /**
5315
- * This error indicates that the promptbook can not retrieve knowledge from external sources
5316
- *
5317
- * @public exported from `@promptbook/core`
5318
- */
5319
- var KnowledgeScrapeError = /** @class */ (function (_super) {
5320
- __extends(KnowledgeScrapeError, _super);
5321
- function KnowledgeScrapeError(message) {
5322
- var _this = _super.call(this, message) || this;
5323
- _this.name = 'KnowledgeScrapeError';
5324
- Object.setPrototypeOf(_this, KnowledgeScrapeError.prototype);
5325
- return _this;
5326
- }
5327
- return KnowledgeScrapeError;
5328
- }(Error));
5329
-
5330
- /**
5331
- * This error type indicates that some limit was reached
5332
- *
5333
- * @public exported from `@promptbook/core`
5334
- */
5335
- var LimitReachedError = /** @class */ (function (_super) {
5336
- __extends(LimitReachedError, _super);
5337
- function LimitReachedError(message) {
5338
- var _this = _super.call(this, message) || this;
5339
- _this.name = 'LimitReachedError';
5340
- Object.setPrototypeOf(_this, LimitReachedError.prototype);
5341
- return _this;
5342
- }
5343
- return LimitReachedError;
5344
- }(Error));
5345
-
5346
- /**
5347
- * This error type indicates that some tools are missing for pipeline execution or preparation
5348
- *
5349
- * @public exported from `@promptbook/core`
5350
- */
5351
- var MissingToolsError = /** @class */ (function (_super) {
5352
- __extends(MissingToolsError, _super);
5353
- function MissingToolsError(message) {
5354
- var _this = _super.call(this, spaceTrim.spaceTrim(function (block) { return "\n ".concat(block(message), "\n\n Note: You have probbably forgot to provide some tools for pipeline execution or preparation\n\n "); })) || this;
5355
- _this.name = 'MissingToolsError';
5356
- Object.setPrototypeOf(_this, MissingToolsError.prototype);
5357
- return _this;
5358
- }
5359
- return MissingToolsError;
5360
- }(Error));
5361
-
5362
- /**
5363
- * This error indicates that promptbook not found in the collection
5364
- *
5365
- * @public exported from `@promptbook/core`
5366
- */
5367
- var NotFoundError = /** @class */ (function (_super) {
5368
- __extends(NotFoundError, _super);
5369
- function NotFoundError(message) {
5370
- var _this = _super.call(this, message) || this;
5371
- _this.name = 'NotFoundError';
5372
- Object.setPrototypeOf(_this, NotFoundError.prototype);
5373
- return _this;
5374
- }
5375
- return NotFoundError;
5376
- }(Error));
5377
-
5378
- /**
5379
- * This error indicates errors during the execution of the pipeline
5380
- *
5381
- * @public exported from `@promptbook/core`
5382
- */
5383
- var PipelineExecutionError = /** @class */ (function (_super) {
5384
- __extends(PipelineExecutionError, _super);
5385
- function PipelineExecutionError(message) {
5386
- var _this = _super.call(this, message) || this;
5387
- _this.name = 'PipelineExecutionError';
5388
- Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
5389
- return _this;
5390
- }
5391
- return PipelineExecutionError;
5392
- }(Error));
5393
-
5394
- /**
5395
- * This error indicates that the promptbook object has valid syntax (=can be parsed) but contains logical errors (like circular dependencies)
5396
- *
5397
- * @public exported from `@promptbook/core`
5398
- */
5399
- var PipelineLogicError = /** @class */ (function (_super) {
5400
- __extends(PipelineLogicError, _super);
5401
- function PipelineLogicError(message) {
5402
- var _this = _super.call(this, message) || this;
5403
- _this.name = 'PipelineLogicError';
5404
- Object.setPrototypeOf(_this, PipelineLogicError.prototype);
5405
- return _this;
5406
- }
5407
- return PipelineLogicError;
5408
- }(Error));
5409
-
5410
- /**
5411
- * This error indicates errors in referencing promptbooks between each other
5412
- *
5413
- * @public exported from `@promptbook/core`
5414
- */
5415
- var PipelineUrlError = /** @class */ (function (_super) {
5416
- __extends(PipelineUrlError, _super);
5417
- function PipelineUrlError(message) {
5418
- var _this = _super.call(this, message) || this;
5419
- _this.name = 'PipelineUrlError';
5420
- Object.setPrototypeOf(_this, PipelineUrlError.prototype);
5421
- return _this;
5422
- }
5423
- return PipelineUrlError;
5424
- }(Error));
5425
-
5426
- /**
5427
- * Index of all custom errors
5428
- *
5429
- * @public exported from `@promptbook/core`
5430
- */
5431
- var PROMPTBOOK_ERRORS = {
5432
- AbstractFormatError: AbstractFormatError,
5433
- CsvFormatError: CsvFormatError,
5434
- CollectionError: CollectionError,
5435
- EnvironmentMismatchError: EnvironmentMismatchError,
5436
- ExpectError: ExpectError,
5437
- KnowledgeScrapeError: KnowledgeScrapeError,
5438
- LimitReachedError: LimitReachedError,
5439
- MissingToolsError: MissingToolsError,
5440
- NotFoundError: NotFoundError,
5441
- NotYetImplementedError: NotYetImplementedError,
5442
- ParseError: ParseError,
5443
- PipelineExecutionError: PipelineExecutionError,
5444
- PipelineLogicError: PipelineLogicError,
5445
- PipelineUrlError: PipelineUrlError,
5446
- UnexpectedError: UnexpectedError,
5447
- // TODO: [🪑]> VersionMismatchError,
5448
- };
5449
- /**
5450
- * Index of all javascript errors
5451
- *
5452
- * @private for internal usage
5453
- */
5454
- var COMMON_JAVASCRIPT_ERRORS = {
5455
- Error: Error,
5456
- EvalError: EvalError,
5457
- RangeError: RangeError,
5458
- ReferenceError: ReferenceError,
5459
- SyntaxError: SyntaxError,
5460
- TypeError: TypeError,
5461
- URIError: URIError,
5462
- AggregateError: AggregateError,
5463
- /*
5464
- Note: Not widely supported
5465
- > InternalError,
5466
- > ModuleError,
5467
- > HeapError,
5468
- > WebAssemblyCompileError,
5469
- > WebAssemblyRuntimeError,
5470
- */
5471
- };
5472
- /**
5473
- * Index of all errors
5474
- *
5475
- * @private for internal usage
5476
- */
5477
- var ALL_ERRORS = __assign(__assign({}, PROMPTBOOK_ERRORS), COMMON_JAVASCRIPT_ERRORS);
5478
- /**
5479
- * Note: [💞] Ignore a discrepancy between file name and entity name
5480
- */
5481
-
5482
5566
  /**
5483
- * Deserializes the error object
5484
- *
5485
- * @public exported from `@promptbook/utils`
5567
+ * TODO: !!!! Do not return Promise<PipelineJson> But PreparePipelineTask
5486
5568
  */
5487
- function deserializeError(error) {
5488
- var ErrorClass = ALL_ERRORS[error.name];
5489
- if (ErrorClass === undefined) {
5490
- return new Error("".concat(error.name, ": ").concat(error.message));
5491
- }
5492
- return new ErrorClass(error.message);
5493
- }
5494
5569
 
5495
5570
  /**
5496
5571
  * Remote server is a proxy server that uses its execution tools internally and exposes the executor interface externally.
@@ -5529,7 +5604,7 @@
5529
5604
  var socket;
5530
5605
  return __generator(this, function (_a) {
5531
5606
  switch (_a.label) {
5532
- case 0: return [4 /*yield*/, this.makeConnection()];
5607
+ case 0: return [4 /*yield*/, createRemoteClient(this.options)];
5533
5608
  case 1:
5534
5609
  socket = _a.sent();
5535
5610
  socket.disconnect();
@@ -5546,24 +5621,12 @@
5546
5621
  var socket, promptResult;
5547
5622
  return __generator(this, function (_a) {
5548
5623
  switch (_a.label) {
5549
- case 0: return [4 /*yield*/, this.makeConnection()];
5624
+ case 0: return [4 /*yield*/, createRemoteClient(this.options)];
5550
5625
  case 1:
5551
5626
  socket = _a.sent();
5552
- if (this.options.isAnonymous) {
5553
- socket.emit('listModels-request', {
5554
- isAnonymous: true,
5555
- userId: this.options.userId,
5556
- llmToolsConfiguration: this.options.llmToolsConfiguration,
5557
- } /* <- Note: [🤛] */);
5558
- }
5559
- else {
5560
- socket.emit('listModels-request', {
5561
- isAnonymous: false,
5562
- appId: this.options.appId,
5563
- userId: this.options.userId,
5564
- customOptions: this.options.customOptions,
5565
- } /* <- Note: [🤛] */);
5566
- }
5627
+ socket.emit('listModels-request', {
5628
+ identification: this.options.identification,
5629
+ } /* <- Note: [🤛] */);
5567
5630
  return [4 /*yield*/, new Promise(function (resolve, reject) {
5568
5631
  socket.on('listModels-response', function (response) {
5569
5632
  resolve(response.models);
@@ -5582,29 +5645,6 @@
5582
5645
  });
5583
5646
  });
5584
5647
  };
5585
- /**
5586
- * Creates a connection to the remote proxy server.
5587
- */
5588
- RemoteLlmExecutionTools.prototype.makeConnection = function () {
5589
- var _this = this;
5590
- return new Promise(function (resolve, reject) {
5591
- var socket = socket_ioClient.io(_this.options.remoteUrl, {
5592
- retries: CONNECTION_RETRIES_LIMIT,
5593
- timeout: CONNECTION_TIMEOUT_MS,
5594
- path: _this.options.path,
5595
- // path: `${this.remoteUrl.pathname}/socket.io`,
5596
- transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
5597
- });
5598
- // console.log('Connecting to', this.options.remoteUrl.href, { socket });
5599
- socket.on('connect', function () {
5600
- resolve(socket);
5601
- });
5602
- // TODO: [💩] Better timeout handling
5603
- setTimeout(function () {
5604
- reject(new Error("Timeout while connecting to ".concat(_this.options.remoteUrl)));
5605
- }, CONNECTION_TIMEOUT_MS);
5606
- });
5607
- };
5608
5648
  /**
5609
5649
  * Calls remote proxy server to use a chat model
5610
5650
  */
@@ -5641,26 +5681,13 @@
5641
5681
  var socket, promptResult;
5642
5682
  return __generator(this, function (_a) {
5643
5683
  switch (_a.label) {
5644
- case 0: return [4 /*yield*/, this.makeConnection()];
5684
+ case 0: return [4 /*yield*/, createRemoteClient(this.options)];
5645
5685
  case 1:
5646
5686
  socket = _a.sent();
5647
- if (this.options.isAnonymous) {
5648
- socket.emit('prompt-request', {
5649
- isAnonymous: true,
5650
- userId: this.options.userId,
5651
- llmToolsConfiguration: this.options.llmToolsConfiguration,
5652
- prompt: prompt,
5653
- } /* <- Note: [🤛] */);
5654
- }
5655
- else {
5656
- socket.emit('prompt-request', {
5657
- isAnonymous: false,
5658
- appId: this.options.appId,
5659
- userId: this.options.userId,
5660
- customOptions: this.options.customOptions,
5661
- prompt: prompt,
5662
- } /* <- Note: [🤛] */);
5663
- }
5687
+ socket.emit('prompt-request', {
5688
+ identification: this.options.identification,
5689
+ prompt: prompt,
5690
+ } /* <- Note: [🤛] */);
5664
5691
  return [4 /*yield*/, new Promise(function (resolve, reject) {
5665
5692
  socket.on('prompt-response', function (response) {
5666
5693
  resolve(response.promptResult);