@promptbook/remote-client 0.89.0-2 → 0.89.0-20

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 (48) hide show
  1. package/README.md +10 -6
  2. package/esm/index.es.js +96 -20
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/servers.d.ts +40 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +20 -8
  6. package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
  7. package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
  8. package/esm/typings/src/_packages/types.index.d.ts +18 -16
  9. package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
  10. package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
  11. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +28 -0
  12. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  13. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
  14. package/esm/typings/src/config.d.ts +24 -26
  15. package/esm/typings/src/errors/0-index.d.ts +9 -0
  16. package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
  17. package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
  18. package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
  19. package/esm/typings/src/errors/WrappedError.d.ts +10 -0
  20. package/esm/typings/src/errors/assertsError.d.ts +11 -0
  21. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  22. package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
  23. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
  24. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
  25. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +45 -1
  26. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
  27. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  28. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
  29. package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
  30. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
  31. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  32. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  33. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  34. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  35. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  36. package/esm/typings/src/remote-server/startRemoteServer.d.ts +2 -3
  37. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
  38. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +89 -4
  39. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  40. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  41. package/esm/typings/src/types/typeAliases.d.ts +19 -0
  42. package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
  43. package/package.json +7 -3
  44. package/umd/index.umd.js +96 -20
  45. package/umd/index.umd.js.map +1 -1
  46. package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
  47. package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
  48. package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/README.md CHANGED
@@ -200,7 +200,7 @@ Each part of the book defines one of 3 circles:
200
200
 
201
201
  ### **What:** Workflows, Tasks and Parameters
202
202
 
203
- What work needs to be done. Each book defines a workflow, which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
203
+ What work needs to be done. Each book defines a [workflow *(scenario or pipeline)*](https://github.com/webgptorg/promptbook/discussions/88), which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
204
204
 
205
205
  **Related commands:**
206
206
 
@@ -244,6 +244,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
244
244
 
245
245
 
246
246
 
247
+ ## 🔒 Security
248
+
249
+ For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
250
+
247
251
  ## 📦 Packages _(for developers)_
248
252
 
249
253
  This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
@@ -300,7 +304,7 @@ The following glossary is used to clarify certain concepts:
300
304
  ### General LLM / AI terms
301
305
 
302
306
  - **Prompt drift** is a phenomenon where the AI model starts to generate outputs that are not aligned with the original prompt. This can happen due to the model's training data, the prompt's wording, or the model's architecture.
303
- - **Pipeline, workflow or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.
307
+ - [**Pipeline, workflow scenario or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.](https://github.com/webgptorg/promptbook/discussions/88)
304
308
  - **Fine-tuning** is a process where a pre-trained AI model is further trained on a specific dataset to improve its performance on a specific task.
305
309
  - **Zero-shot learning** is a machine learning paradigm where a model is trained to perform a task without any labeled examples. Instead, the model is provided with a description of the task and is expected to generate the correct output.
306
310
  - **Few-shot learning** is a machine learning paradigm where a model is trained to perform a task with only a few labeled examples. This is in contrast to traditional machine learning, where models are trained on large datasets.
@@ -308,8 +312,6 @@ The following glossary is used to clarify certain concepts:
308
312
  - **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
309
313
  - **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
310
314
 
311
-
312
-
313
315
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
314
316
 
315
317
 
@@ -423,6 +425,8 @@ See [TODO.md](./TODO.md)
423
425
 
424
426
  ## 🖋️ Contributing
425
427
 
426
- We are open to pull requests, feedback, and suggestions.
428
+ You can also ⭐ star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).We are open to [pull requests, feedback, and suggestions](./CONTRIBUTING.md).
429
+
430
+ ## 📞 Support
427
431
 
428
- You can also star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).
432
+ If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
package/esm/index.es.js CHANGED
@@ -20,7 +20,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
20
20
  * @generated
21
21
  * @see https://github.com/webgptorg/promptbook
22
22
  */
23
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-2';
23
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-20';
24
24
  /**
25
25
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
26
26
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -56,6 +56,19 @@ class CsvFormatError extends AbstractFormatError {
56
56
  }
57
57
  }
58
58
 
59
+ /**
60
+ * AuthenticationError is thrown from login function which is dependency of remote server
61
+ *
62
+ * @public exported from `@promptbook/core`
63
+ */
64
+ class AuthenticationError extends Error {
65
+ constructor(message) {
66
+ super(message);
67
+ this.name = 'AuthenticationError';
68
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
69
+ }
70
+ }
71
+
59
72
  /**
60
73
  * This error indicates that the pipeline collection cannot be propperly loaded
61
74
  *
@@ -225,7 +238,7 @@ class PipelineExecutionError extends Error {
225
238
  }
226
239
  }
227
240
  /**
228
- * TODO: !!!!!! Add id to all errors
241
+ * TODO: [🧠][🌂] Add id to all errors
229
242
  */
230
243
 
231
244
  /**
@@ -254,6 +267,19 @@ class PipelineUrlError extends Error {
254
267
  }
255
268
  }
256
269
 
270
+ /**
271
+ * Error thrown when a fetch request fails
272
+ *
273
+ * @public exported from `@promptbook/core`
274
+ */
275
+ class PromptbookFetchError extends Error {
276
+ constructor(message) {
277
+ super(message);
278
+ this.name = 'PromptbookFetchError';
279
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
280
+ }
281
+ }
282
+
257
283
  /**
258
284
  * Returns the same value that is passed as argument.
259
285
  * No side effects.
@@ -294,6 +320,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
294
320
  * @public exported from `@promptbook/core`
295
321
  */
296
322
  const ADMIN_GITHUB_NAME = 'hejny';
323
+ // <- TODO: [🐊] Pick the best claim
297
324
  /**
298
325
  * When the title is not provided, the default title is used
299
326
  *
@@ -346,7 +373,7 @@ Object.freeze({
346
373
  });
347
374
  /**
348
375
  * Note: [💞] Ignore a discrepancy between file name and entity name
349
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
376
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
350
377
  */
351
378
 
352
379
  /**
@@ -417,6 +444,26 @@ class UnexpectedError extends Error {
417
444
  }
418
445
  }
419
446
 
447
+ /**
448
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
449
+ *
450
+ * @public exported from `@promptbook/core`
451
+ */
452
+ class WrappedError extends Error {
453
+ constructor(whatWasThrown) {
454
+ const tag = `[🤮]`;
455
+ console.error(tag, whatWasThrown);
456
+ super(spaceTrim(`
457
+ Non-Error object was thrown
458
+
459
+ Note: Look for ${tag} in the console for more details
460
+ Please report issue on ${ADMIN_EMAIL}
461
+ `));
462
+ this.name = 'WrappedError';
463
+ Object.setPrototypeOf(this, WrappedError.prototype);
464
+ }
465
+ }
466
+
420
467
  /**
421
468
  * Index of all custom errors
422
469
  *
@@ -437,7 +484,10 @@ const PROMPTBOOK_ERRORS = {
437
484
  PipelineExecutionError,
438
485
  PipelineLogicError,
439
486
  PipelineUrlError,
487
+ AuthenticationError,
488
+ PromptbookFetchError,
440
489
  UnexpectedError,
490
+ WrappedError,
441
491
  // TODO: [🪑]> VersionMismatchError,
442
492
  };
443
493
  /**
@@ -510,22 +560,26 @@ function deserializeError(error) {
510
560
  * @private internal utility function
511
561
  */
512
562
  async function createRemoteClient(options) {
513
- const { remoteUrl, path } = options;
563
+ const { remoteServerUrl } = options;
564
+ let path = new URL(remoteServerUrl).pathname;
565
+ if (path.endsWith('/')) {
566
+ path = path.slice(0, -1);
567
+ }
568
+ path = `${path}/socket.io`;
514
569
  return new Promise((resolve, reject) => {
515
- const socket = io(remoteUrl, {
570
+ const socket = io(remoteServerUrl, {
516
571
  retries: CONNECTION_RETRIES_LIMIT,
517
572
  timeout: CONNECTION_TIMEOUT_MS,
518
573
  path,
519
- // path: `${this.remoteUrl.pathname}/socket.io`,
520
574
  transports: [/*'websocket', <- TODO: [🌬] Make websocket transport work */ 'polling'],
521
575
  });
522
- // console.log('Connecting to', this.options.remoteUrl.href, { socket });
576
+ // console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
523
577
  socket.on('connect', () => {
524
578
  resolve(socket);
525
579
  });
526
580
  // TODO: [💩] Better timeout handling
527
581
  setTimeout(() => {
528
- reject(new Error(`Timeout while connecting to ${remoteUrl}`));
582
+ reject(new Error(`Timeout while connecting to ${remoteServerUrl}`));
529
583
  }, CONNECTION_TIMEOUT_MS);
530
584
  });
531
585
  }
@@ -1507,6 +1561,34 @@ const bookVersionCommandParser = {
1507
1561
  },
1508
1562
  };
1509
1563
 
1564
+ /**
1565
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
1566
+ *
1567
+ * @param whatWasThrown Any object that was thrown
1568
+ * @returns Nothing if the error is an instance of `Error`
1569
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
1570
+ *
1571
+ * @private within the repository
1572
+ */
1573
+ function assertsError(whatWasThrown) {
1574
+ // Case 1: Handle error which was rethrown as `WrappedError`
1575
+ if (whatWasThrown instanceof WrappedError) {
1576
+ const wrappedError = whatWasThrown;
1577
+ throw wrappedError;
1578
+ }
1579
+ // Case 2: Handle unexpected errors
1580
+ if (whatWasThrown instanceof UnexpectedError) {
1581
+ const unexpectedError = whatWasThrown;
1582
+ throw unexpectedError;
1583
+ }
1584
+ // Case 3: Handle standard errors - keep them up to consumer
1585
+ if (whatWasThrown instanceof Error) {
1586
+ return;
1587
+ }
1588
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
1589
+ throw new WrappedError(whatWasThrown);
1590
+ }
1591
+
1510
1592
  /**
1511
1593
  * Units of text measurement
1512
1594
  *
@@ -1587,6 +1669,8 @@ function parseNumber(value) {
1587
1669
  */
1588
1670
 
1589
1671
  /**
1672
+ import { WrappedError } from '../../errors/WrappedError';
1673
+ import { assertsError } from '../../errors/assertsError';
1590
1674
  * Parses the expect command
1591
1675
  *
1592
1676
  * @see `documentationUrl` for more details
@@ -1678,9 +1762,7 @@ const expectCommandParser = {
1678
1762
  };
1679
1763
  }
1680
1764
  catch (error) {
1681
- if (!(error instanceof Error)) {
1682
- throw error;
1683
- }
1765
+ assertsError(error);
1684
1766
  throw new ParseError(spaceTrim$1((block) => `
1685
1767
  Invalid FORMAT command
1686
1768
  ${block(error.message)}:
@@ -1837,9 +1919,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
1837
1919
  return true;
1838
1920
  }
1839
1921
  catch (error) {
1840
- if (!(error instanceof Error)) {
1841
- throw error;
1842
- }
1922
+ assertsError(error);
1843
1923
  if (error.message.includes('Unexpected token')) {
1844
1924
  return false;
1845
1925
  }
@@ -2157,9 +2237,7 @@ function checkSerializableAsJson(options) {
2157
2237
  JSON.stringify(value); // <- TODO: [0]
2158
2238
  }
2159
2239
  catch (error) {
2160
- if (!(error instanceof Error)) {
2161
- throw error;
2162
- }
2240
+ assertsError(error);
2163
2241
  throw new UnexpectedError(spaceTrim$1((block) => `
2164
2242
  \`${name}\` is not serializable
2165
2243
 
@@ -4814,9 +4892,7 @@ function extractVariablesFromJavascript(script) {
4814
4892
  }
4815
4893
  }
4816
4894
  catch (error) {
4817
- if (!(error instanceof Error)) {
4818
- throw error;
4819
- }
4895
+ assertsError(error);
4820
4896
  throw new ParseError(spaceTrim((block) => `
4821
4897
  Can not extract variables from the script
4822
4898
  ${block(error.stack || error.message)}