@promptbook/markitdown 0.89.0-3 → 0.89.0-31

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 (50) hide show
  1. package/README.md +9 -7
  2. package/esm/index.es.js +122 -39
  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 +24 -12
  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/openapi-types.d.ts +284 -0
  31. package/esm/typings/src/remote-server/openapi.d.ts +187 -0
  32. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
  33. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  34. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  35. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  36. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  37. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  38. package/esm/typings/src/remote-server/startRemoteServer.d.ts +3 -4
  39. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
  40. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +84 -9
  41. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  42. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  43. package/esm/typings/src/types/typeAliases.d.ts +19 -0
  44. package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
  45. package/package.json +9 -5
  46. package/umd/index.umd.js +122 -39
  47. package/umd/index.umd.js.map +1 -1
  48. package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
  49. package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
  50. package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
package/README.md CHANGED
@@ -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,10 +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
-
314
-
315
315
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
316
316
 
317
317
 
@@ -425,6 +425,8 @@ See [TODO.md](./TODO.md)
425
425
 
426
426
  ## 🖋️ Contributing
427
427
 
428
- 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
429
431
 
430
- 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
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-3';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-31';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -89,6 +89,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
89
89
  * @public exported from `@promptbook/core`
90
90
  */
91
91
  const ADMIN_GITHUB_NAME = 'hejny';
92
+ // <- TODO: [🐊] Pick the best claim
92
93
  /**
93
94
  * When the title is not provided, the default title is used
94
95
  *
@@ -121,6 +122,7 @@ const VALUE_STRINGS = {
121
122
  infinity: '(infinity; ∞)',
122
123
  negativeInfinity: '(negative infinity; -∞)',
123
124
  unserializable: '(unserializable value)',
125
+ circular: '(circular JSON)',
124
126
  };
125
127
  /**
126
128
  * Small number limit
@@ -160,6 +162,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
160
162
  */
161
163
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
162
164
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
165
+ // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
163
166
  /**
164
167
  * Where to store the temporary downloads
165
168
  *
@@ -211,7 +214,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
211
214
  true);
212
215
  /**
213
216
  * Note: [💞] Ignore a discrepancy between file name and entity name
214
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
217
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
215
218
  */
216
219
 
217
220
  /**
@@ -877,6 +880,54 @@ class ParseError extends Error {
877
880
  * TODO: Maybe split `ParseError` and `ApplyError`
878
881
  */
879
882
 
883
+ /**
884
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
885
+ *
886
+ * @public exported from `@promptbook/core`
887
+ */
888
+ class WrappedError extends Error {
889
+ constructor(whatWasThrown) {
890
+ const tag = `[🤮]`;
891
+ console.error(tag, whatWasThrown);
892
+ super(spaceTrim$1(`
893
+ Non-Error object was thrown
894
+
895
+ Note: Look for ${tag} in the console for more details
896
+ Please report issue on ${ADMIN_EMAIL}
897
+ `));
898
+ this.name = 'WrappedError';
899
+ Object.setPrototypeOf(this, WrappedError.prototype);
900
+ }
901
+ }
902
+
903
+ /**
904
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
905
+ *
906
+ * @param whatWasThrown Any object that was thrown
907
+ * @returns Nothing if the error is an instance of `Error`
908
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
909
+ *
910
+ * @private within the repository
911
+ */
912
+ function assertsError(whatWasThrown) {
913
+ // Case 1: Handle error which was rethrown as `WrappedError`
914
+ if (whatWasThrown instanceof WrappedError) {
915
+ const wrappedError = whatWasThrown;
916
+ throw wrappedError;
917
+ }
918
+ // Case 2: Handle unexpected errors
919
+ if (whatWasThrown instanceof UnexpectedError) {
920
+ const unexpectedError = whatWasThrown;
921
+ throw unexpectedError;
922
+ }
923
+ // Case 3: Handle standard errors - keep them up to consumer
924
+ if (whatWasThrown instanceof Error) {
925
+ return;
926
+ }
927
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
928
+ throw new WrappedError(whatWasThrown);
929
+ }
930
+
880
931
  /**
881
932
  * Function isValidJsonString will tell you if the string is valid JSON or not
882
933
  *
@@ -888,9 +939,7 @@ function isValidJsonString(value /* <- [👨‍⚖️] */) {
888
939
  return true;
889
940
  }
890
941
  catch (error) {
891
- if (!(error instanceof Error)) {
892
- throw error;
893
- }
942
+ assertsError(error);
894
943
  if (error.message.includes('Unexpected token')) {
895
944
  return false;
896
945
  }
@@ -1243,9 +1292,7 @@ function checkSerializableAsJson(options) {
1243
1292
  JSON.stringify(value); // <- TODO: [0]
1244
1293
  }
1245
1294
  catch (error) {
1246
- if (!(error instanceof Error)) {
1247
- throw error;
1248
- }
1295
+ assertsError(error);
1249
1296
  throw new UnexpectedError(spaceTrim((block) => `
1250
1297
  \`${name}\` is not serializable
1251
1298
 
@@ -2034,7 +2081,7 @@ class PipelineExecutionError extends Error {
2034
2081
  }
2035
2082
  }
2036
2083
  /**
2037
- * TODO: !!!!!! Add id to all errors
2084
+ * TODO: [🧠][🌂] Add id to all errors
2038
2085
  */
2039
2086
 
2040
2087
  /**
@@ -2134,6 +2181,19 @@ class CsvFormatError extends AbstractFormatError {
2134
2181
  }
2135
2182
  }
2136
2183
 
2184
+ /**
2185
+ * AuthenticationError is thrown from login function which is dependency of remote server
2186
+ *
2187
+ * @public exported from `@promptbook/core`
2188
+ */
2189
+ class AuthenticationError extends Error {
2190
+ constructor(message) {
2191
+ super(message);
2192
+ this.name = 'AuthenticationError';
2193
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
2194
+ }
2195
+ }
2196
+
2137
2197
  /**
2138
2198
  * This error indicates that the pipeline collection cannot be propperly loaded
2139
2199
  *
@@ -2199,6 +2259,19 @@ class NotYetImplementedError extends Error {
2199
2259
  }
2200
2260
  }
2201
2261
 
2262
+ /**
2263
+ * Error thrown when a fetch request fails
2264
+ *
2265
+ * @public exported from `@promptbook/core`
2266
+ */
2267
+ class PromptbookFetchError extends Error {
2268
+ constructor(message) {
2269
+ super(message);
2270
+ this.name = 'PromptbookFetchError';
2271
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
2272
+ }
2273
+ }
2274
+
2202
2275
  /**
2203
2276
  * Index of all custom errors
2204
2277
  *
@@ -2219,7 +2292,10 @@ const PROMPTBOOK_ERRORS = {
2219
2292
  PipelineExecutionError,
2220
2293
  PipelineLogicError,
2221
2294
  PipelineUrlError,
2295
+ AuthenticationError,
2296
+ PromptbookFetchError,
2222
2297
  UnexpectedError,
2298
+ WrappedError,
2223
2299
  // TODO: [🪑]> VersionMismatchError,
2224
2300
  };
2225
2301
  /**
@@ -2358,8 +2434,8 @@ function createTask(options) {
2358
2434
  updatedAt = new Date();
2359
2435
  errors.push(...executionResult.errors);
2360
2436
  warnings.push(...executionResult.warnings);
2361
- // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2362
- // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2437
+ // <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
2438
+ // TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2363
2439
  // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2364
2440
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2365
2441
  assertsTaskSuccessful(executionResult);
@@ -2369,6 +2445,7 @@ function createTask(options) {
2369
2445
  partialResultSubject.next(executionResult);
2370
2446
  }
2371
2447
  catch (error) {
2448
+ assertsError(error);
2372
2449
  status = 'ERROR';
2373
2450
  errors.push(error);
2374
2451
  partialResultSubject.error(error);
@@ -2435,6 +2512,10 @@ function serializeError(error) {
2435
2512
 
2436
2513
  Cannot serialize error with name "${name}"
2437
2514
 
2515
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2516
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2517
+
2518
+
2438
2519
  ${block(stack || message)}
2439
2520
 
2440
2521
  `));
@@ -2756,14 +2837,15 @@ class MultipleLlmExecutionTools {
2756
2837
  }
2757
2838
  }
2758
2839
  catch (error) {
2759
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
2840
+ assertsError(error);
2841
+ if (error instanceof UnexpectedError) {
2760
2842
  throw error;
2761
2843
  }
2762
2844
  errors.push({ llmExecutionTools, error });
2763
2845
  }
2764
2846
  }
2765
2847
  if (errors.length === 1) {
2766
- throw errors[0];
2848
+ throw errors[0].error;
2767
2849
  }
2768
2850
  else if (errors.length > 1) {
2769
2851
  throw new PipelineExecutionError(
@@ -3211,17 +3293,22 @@ function mimeTypeToExtension(value) {
3211
3293
  /**
3212
3294
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3213
3295
  *
3214
- * @private as default `fetch` function used in Promptbook scrapers
3296
+ * @public exported from `@promptbook/core`
3215
3297
  */
3216
- const scraperFetch = async (url, init) => {
3298
+ const promptbookFetch = async (urlOrRequest, init) => {
3217
3299
  try {
3218
- return await fetch(url, init);
3300
+ return await fetch(urlOrRequest, init);
3219
3301
  }
3220
3302
  catch (error) {
3221
- if (!(error instanceof Error)) {
3222
- throw error;
3303
+ assertsError(error);
3304
+ let url;
3305
+ if (typeof urlOrRequest === 'string') {
3306
+ url = urlOrRequest;
3307
+ }
3308
+ else if (urlOrRequest instanceof Request) {
3309
+ url = urlOrRequest.url;
3223
3310
  }
3224
- throw new KnowledgeScrapeError(spaceTrim((block) => `
3311
+ throw new PromptbookFetchError(spaceTrim((block) => `
3225
3312
  Can not fetch "${url}"
3226
3313
 
3227
3314
  Fetch error:
@@ -3242,7 +3329,7 @@ const scraperFetch = async (url, init) => {
3242
3329
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3243
3330
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
3244
3331
  var _a;
3245
- const { fetch = scraperFetch } = tools;
3332
+ const { fetch = promptbookFetch } = tools;
3246
3333
  const { knowledgeSourceContent } = knowledgeSource;
3247
3334
  let { name } = knowledgeSource;
3248
3335
  const { rootDirname = null,
@@ -3444,9 +3531,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
3444
3531
  knowledgePreparedUnflatten[index] = pieces;
3445
3532
  }
3446
3533
  catch (error) {
3447
- if (!(error instanceof Error)) {
3448
- throw error;
3449
- }
3534
+ assertsError(error);
3450
3535
  console.warn(error);
3451
3536
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3452
3537
  }
@@ -3738,13 +3823,19 @@ function valueToString(value) {
3738
3823
  return value.toISOString();
3739
3824
  }
3740
3825
  else {
3741
- return JSON.stringify(value);
3826
+ try {
3827
+ return JSON.stringify(value);
3828
+ }
3829
+ catch (error) {
3830
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
3831
+ return VALUE_STRINGS.circular;
3832
+ }
3833
+ throw error;
3834
+ }
3742
3835
  }
3743
3836
  }
3744
3837
  catch (error) {
3745
- if (!(error instanceof Error)) {
3746
- throw error;
3747
- }
3838
+ assertsError(error);
3748
3839
  console.error(error);
3749
3840
  return VALUE_STRINGS.unserializable;
3750
3841
  }
@@ -3801,9 +3892,7 @@ function extractVariablesFromJavascript(script) {
3801
3892
  }
3802
3893
  }
3803
3894
  catch (error) {
3804
- if (!(error instanceof Error)) {
3805
- throw error;
3806
- }
3895
+ assertsError(error);
3807
3896
  throw new ParseError(spaceTrim$1((block) => `
3808
3897
  Can not extract variables from the script
3809
3898
  ${block(error.stack || error.message)}
@@ -4668,9 +4757,7 @@ async function executeAttempts(options) {
4668
4757
  break scripts;
4669
4758
  }
4670
4759
  catch (error) {
4671
- if (!(error instanceof Error)) {
4672
- throw error;
4673
- }
4760
+ assertsError(error);
4674
4761
  if (error instanceof UnexpectedError) {
4675
4762
  throw error;
4676
4763
  }
@@ -4740,9 +4827,7 @@ async function executeAttempts(options) {
4740
4827
  break scripts;
4741
4828
  }
4742
4829
  catch (error) {
4743
- if (!(error instanceof Error)) {
4744
- throw error;
4745
- }
4830
+ assertsError(error);
4746
4831
  if (error instanceof UnexpectedError) {
4747
4832
  throw error;
4748
4833
  }
@@ -5363,9 +5448,7 @@ async function executePipeline(options) {
5363
5448
  await Promise.all(resolving);
5364
5449
  }
5365
5450
  catch (error /* <- Note: [3] */) {
5366
- if (!(error instanceof Error)) {
5367
- throw error;
5368
- }
5451
+ assertsError(error);
5369
5452
  // Note: No need to rethrow UnexpectedError
5370
5453
  // if (error instanceof UnexpectedError) {
5371
5454
  // Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹‍♂️]