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

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