@promptbook/markdown-utils 0.89.0-1 → 0.89.0-11

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 (52) hide show
  1. package/README.md +3 -1
  2. package/esm/index.es.js +152 -86
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +16 -4
  5. package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
  6. package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
  7. package/esm/typings/src/_packages/types.index.d.ts +18 -20
  8. package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
  9. package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
  10. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +15 -0
  11. package/esm/typings/src/config.d.ts +15 -8
  12. package/esm/typings/src/errors/0-index.d.ts +6 -0
  13. package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
  14. package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
  15. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
  16. package/esm/typings/src/execution/PromptResult.d.ts +2 -2
  17. package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
  18. package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
  19. package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
  20. package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
  21. package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
  22. package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
  23. package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
  24. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
  25. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
  26. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +36 -1
  27. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
  28. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
  29. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
  30. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  31. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
  32. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
  33. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
  34. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
  35. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
  36. package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
  37. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
  38. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  39. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  40. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  41. package/esm/typings/src/remote-server/startRemoteServer.d.ts +2 -2
  42. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
  43. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +73 -3
  44. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  45. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +37 -0
  46. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  47. package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
  48. package/package.json +1 -1
  49. package/umd/index.umd.js +152 -86
  50. package/umd/index.umd.js.map +1 -1
  51. package/esm/typings/src/playground/BrjappConnector.d.ts +0 -64
  52. package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
@@ -1,10 +1,15 @@
1
+ import type { Request, Response } from 'express';
1
2
  import type { Promisable } from 'type-fest';
2
3
  import type { PipelineCollection } from '../../collection/PipelineCollection';
4
+ import { AuthenticationError } from '../../errors/AuthenticationError';
3
5
  import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
4
6
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
5
7
  import type { string_app_id } from '../../types/typeAliases';
8
+ import type { string_email } from '../../types/typeAliases';
9
+ import type { string_password } from '../../types/typeAliases';
6
10
  import type { string_uri } from '../../types/typeAliases';
7
11
  import type { string_user_id } from '../../types/typeAliases';
12
+ import type { Identification } from '../socket-types/_subtypes/Identification';
8
13
  /**
9
14
  * @@@
10
15
  *
@@ -16,7 +21,6 @@ import type { string_user_id } from '../../types/typeAliases';
16
21
  *
17
22
  * You can enable both modes at the same time.
18
23
  *
19
- * @public exported from `@promptbook/remote-client`
20
24
  * @public exported from `@promptbook/remote-server`
21
25
  */
22
26
  export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
@@ -32,8 +36,12 @@ export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
32
36
  * @default '/'
33
37
  * @example '/api/promptbook/'
34
38
  */
35
- readonly rootPath: string_uri;
36
- } & (AnonymousRemoteServerOptions | ApplicationRemoteServerOptions<TCustomOptions> | (AnonymousRemoteServerOptions & ApplicationRemoteServerOptions<TCustomOptions>));
39
+ readonly rootPath?: string_uri;
40
+ } & ((AnonymousRemoteServerOptions & {
41
+ readonly isApplicationModeAllowed?: false;
42
+ }) | ({
43
+ readonly isAnonymousModeAllowed?: false;
44
+ } & ApplicationRemoteServerOptions<TCustomOptions>) | (AnonymousRemoteServerOptions & ApplicationRemoteServerOptions<TCustomOptions>));
37
45
  export type AnonymousRemoteServerOptions = {
38
46
  /**
39
47
  * Enable anonymous mode
@@ -51,6 +59,18 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
51
59
  * This is used to check validity of the prompt to prevent misuse
52
60
  */
53
61
  readonly collection: PipelineCollection;
62
+ /**
63
+ * User tries to login to the server, this function will be called verify the user and return the identification or throw an error
64
+ * This can be also doubled as a function to register the user
65
+ *
66
+ * Note: In most cases, you will return `PromptbookServer_ApplicationIdentification`
67
+ * `PromptbookServer_AnonymousIdentification` is useful only in scenarios when user stores its own api keys on the application server and
68
+ * server acts only as a api key provider
69
+ *
70
+ * Note: In most cases DO NOT THROW `AuthenticationError` but return `isSuccess: false` with message
71
+ * @throws `AuthenticationError` if the user is not allowed to login for example because of invalid credentials
72
+ */
73
+ login(loginRequest: LoginRequest): Promise<LoginResponse<TCustomOptions>>;
54
74
  /**
55
75
  * Creates llm execution tools for each client
56
76
  */
@@ -82,6 +102,56 @@ export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
82
102
  */
83
103
  readonly customOptions?: TCustomOptions;
84
104
  };
105
+ /**
106
+ * Login request for the application mode
107
+ */
108
+ export type LoginRequest = {
109
+ /**
110
+ * Identifier of the application you are using
111
+ *
112
+ * Note: This is usefull when you use Promptbook remote server for multiple apps/frontends, if its used just for single app, use here just "app" or "your-app-name"
113
+ */
114
+ readonly appId: string_app_id | null;
115
+ /**
116
+ * Username (for example email) of the user
117
+ */
118
+ readonly username: string_email | string;
119
+ /**
120
+ * Password of the user
121
+ */
122
+ readonly password: string_password;
123
+ /**
124
+ * Request object from express if you want to access some request data for example headers, IP address, etc.
125
+ */
126
+ readonly rawRequest: Request;
127
+ /**
128
+ * Response object from express if you want to add some custom headers.
129
+ *
130
+ * Note: It is not recommended to use this object to send body of the response because it can confuse the client
131
+ */
132
+ readonly rawResponse: Response;
133
+ };
134
+ /**
135
+ * Login response for the application mode
136
+ */
137
+ export type LoginResponse<TCustomOptions> = {
138
+ /**
139
+ * Was the login successful
140
+ */
141
+ readonly isSuccess: boolean;
142
+ /**
143
+ * Message to display to the user, this message is always displayed
144
+ */
145
+ readonly message?: string;
146
+ /**
147
+ * Optional error if the login was not successful
148
+ */
149
+ readonly error?: AuthenticationError;
150
+ /**
151
+ * Identification of the user to be used in the future requests
152
+ */
153
+ readonly identification?: Identification<TCustomOptions>;
154
+ };
85
155
  /**
86
156
  * TODO: Constrain anonymous mode for specific models / providers
87
157
  */
@@ -2,9 +2,9 @@ import type { PromptbookFetch } from '../../../execution/PromptbookFetch';
2
2
  /**
3
3
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
4
4
  *
5
- * @private as default `fetch` function used in Promptbook scrapers
5
+ * @public exported from `@promptbook/core`
6
6
  */
7
- export declare const scraperFetch: PromptbookFetch;
7
+ export declare const promptbookFetch: PromptbookFetch;
8
8
  /**
9
9
  * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
10
10
  */
@@ -0,0 +1,37 @@
1
+ import type { PromptbookStorage } from '../_common/PromptbookStorage';
2
+ /**
3
+ * Stores data in .env variables (Remove !!! nonce 1)
4
+ *
5
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file and also writes to `process.env`
6
+ *
7
+ * @private within the repository - for CLI utils
8
+ */
9
+ export declare class $EnvStorage<TItem> implements PromptbookStorage<TItem> {
10
+ private envFilename;
11
+ private $provideOrCreateEnvFile;
12
+ private transformKey;
13
+ /**
14
+ * Returns the number of key/value pairs currently present in the list associated with the object.
15
+ */
16
+ get length(): number;
17
+ /**
18
+ * Empties the list associated with the object of all key/value pairs, if there are any.
19
+ */
20
+ clear(): void;
21
+ /**
22
+ * Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
23
+ */
24
+ getItem(key: string): Promise<TItem | null>;
25
+ /**
26
+ * Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
27
+ */
28
+ key(index: number): string | null;
29
+ /**
30
+ * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
31
+ */
32
+ setItem(key: string, value: TItem): Promise<void>;
33
+ /**
34
+ * Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
35
+ */
36
+ removeItem(key: string): void;
37
+ }
@@ -242,6 +242,12 @@ export type string_promptbook_documentation_url = `https://github.com/webgptorg/
242
242
  * For example `"towns.cz"`
243
243
  */
244
244
  export type string_domain = string;
245
+ /**
246
+ * Semantic helper
247
+ *
248
+ * For example `"https://*.pavolhejny.com/*"`
249
+ */
250
+ export type string_origin = string;
245
251
  /**
246
252
  * Semantic helper
247
253
  *
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Organizational helper to better mark the place where the more specific type is missing
3
+ *
4
+ * @private within the repository
5
+ */
6
+ export type TODO_narrow<T> = T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/markdown-utils",
3
- "version": "0.89.0-1",
3
+ "version": "0.89.0-11",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -661,6 +661,7 @@
661
661
  */
662
662
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
663
663
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
664
+ // TODO: !!!!!! Just .promptbook dir, hardocode others
664
665
  /**
665
666
  * Where to store the temporary downloads
666
667
  *
@@ -712,7 +713,7 @@
712
713
  true);
713
714
  /**
714
715
  * Note: [💞] Ignore a discrepancy between file name and entity name
715
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
716
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
716
717
  */
717
718
 
718
719
  /**
@@ -1807,6 +1808,19 @@
1807
1808
  }
1808
1809
  }
1809
1810
 
1811
+ /**
1812
+ * AuthenticationError is thrown from login function which is dependency of remote server
1813
+ *
1814
+ * @public exported from `@promptbook/core`
1815
+ */
1816
+ class AuthenticationError extends Error {
1817
+ constructor(message) {
1818
+ super(message);
1819
+ this.name = 'AuthenticationError';
1820
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
1821
+ }
1822
+ }
1823
+
1810
1824
  /**
1811
1825
  * This error indicates that the pipeline collection cannot be propperly loaded
1812
1826
  *
@@ -1898,6 +1912,19 @@
1898
1912
  }
1899
1913
  }
1900
1914
 
1915
+ /**
1916
+ * Error thrown when a fetch request fails
1917
+ *
1918
+ * @public exported from `@promptbook/core`
1919
+ */
1920
+ class PromptbookFetchError extends Error {
1921
+ constructor(message) {
1922
+ super(message);
1923
+ this.name = 'PromptbookFetchError';
1924
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
1925
+ }
1926
+ }
1927
+
1901
1928
  /**
1902
1929
  * Index of all custom errors
1903
1930
  *
@@ -1935,6 +1962,8 @@
1935
1962
  TypeError,
1936
1963
  URIError,
1937
1964
  AggregateError,
1965
+ AuthenticationError,
1966
+ PromptbookFetchError,
1938
1967
  /*
1939
1968
  Note: Not widely supported
1940
1969
  > InternalError,
@@ -1996,6 +2025,7 @@
1996
2025
  const { isSuccessful, errors, warnings } = executionResult;
1997
2026
  for (const warning of warnings) {
1998
2027
  console.warn(warning.message);
2028
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
1999
2029
  }
2000
2030
  if (isSuccessful === true) {
2001
2031
  return;
@@ -2133,6 +2163,10 @@
2133
2163
 
2134
2164
  Cannot serialize error with name "${name}"
2135
2165
 
2166
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2167
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2168
+
2169
+
2136
2170
  ${block(stack || message)}
2137
2171
 
2138
2172
  `));
@@ -2174,30 +2208,42 @@
2174
2208
  await Promise.all(tasks);
2175
2209
  }
2176
2210
 
2211
+ /**
2212
+ * Represents the uncertain value
2213
+ *
2214
+ * @public exported from `@promptbook/core`
2215
+ */
2216
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2217
+ /**
2218
+ * Represents the uncertain value
2219
+ *
2220
+ * @public exported from `@promptbook/core`
2221
+ */
2222
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2177
2223
  /**
2178
2224
  * Represents the usage with no resources consumed
2179
2225
  *
2180
2226
  * @public exported from `@promptbook/core`
2181
2227
  */
2182
2228
  const ZERO_USAGE = $deepFreeze({
2183
- price: { value: 0 },
2229
+ price: ZERO_VALUE,
2184
2230
  input: {
2185
- tokensCount: { value: 0 },
2186
- charactersCount: { value: 0 },
2187
- wordsCount: { value: 0 },
2188
- sentencesCount: { value: 0 },
2189
- linesCount: { value: 0 },
2190
- paragraphsCount: { value: 0 },
2191
- pagesCount: { value: 0 },
2231
+ tokensCount: ZERO_VALUE,
2232
+ charactersCount: ZERO_VALUE,
2233
+ wordsCount: ZERO_VALUE,
2234
+ sentencesCount: ZERO_VALUE,
2235
+ linesCount: ZERO_VALUE,
2236
+ paragraphsCount: ZERO_VALUE,
2237
+ pagesCount: ZERO_VALUE,
2192
2238
  },
2193
2239
  output: {
2194
- tokensCount: { value: 0 },
2195
- charactersCount: { value: 0 },
2196
- wordsCount: { value: 0 },
2197
- sentencesCount: { value: 0 },
2198
- linesCount: { value: 0 },
2199
- paragraphsCount: { value: 0 },
2200
- pagesCount: { value: 0 },
2240
+ tokensCount: ZERO_VALUE,
2241
+ charactersCount: ZERO_VALUE,
2242
+ wordsCount: ZERO_VALUE,
2243
+ sentencesCount: ZERO_VALUE,
2244
+ linesCount: ZERO_VALUE,
2245
+ paragraphsCount: ZERO_VALUE,
2246
+ pagesCount: ZERO_VALUE,
2201
2247
  },
2202
2248
  });
2203
2249
  /**
@@ -2206,24 +2252,24 @@
2206
2252
  * @public exported from `@promptbook/core`
2207
2253
  */
2208
2254
  $deepFreeze({
2209
- price: { value: 0, isUncertain: true },
2255
+ price: UNCERTAIN_ZERO_VALUE,
2210
2256
  input: {
2211
- tokensCount: { value: 0, isUncertain: true },
2212
- charactersCount: { value: 0, isUncertain: true },
2213
- wordsCount: { value: 0, isUncertain: true },
2214
- sentencesCount: { value: 0, isUncertain: true },
2215
- linesCount: { value: 0, isUncertain: true },
2216
- paragraphsCount: { value: 0, isUncertain: true },
2217
- pagesCount: { value: 0, isUncertain: true },
2257
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2258
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2259
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2260
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2261
+ linesCount: UNCERTAIN_ZERO_VALUE,
2262
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2263
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2218
2264
  },
2219
2265
  output: {
2220
- tokensCount: { value: 0, isUncertain: true },
2221
- charactersCount: { value: 0, isUncertain: true },
2222
- wordsCount: { value: 0, isUncertain: true },
2223
- sentencesCount: { value: 0, isUncertain: true },
2224
- linesCount: { value: 0, isUncertain: true },
2225
- paragraphsCount: { value: 0, isUncertain: true },
2226
- pagesCount: { value: 0, isUncertain: true },
2266
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2267
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2268
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2269
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2270
+ linesCount: UNCERTAIN_ZERO_VALUE,
2271
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2272
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2227
2273
  },
2228
2274
  });
2229
2275
  /**
@@ -2511,6 +2557,7 @@
2511
2557
  `);
2512
2558
  // TODO: [🟥] Detect browser / node and make it colorfull
2513
2559
  console.warn(warningMessage);
2560
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2514
2561
  /*
2515
2562
  return {
2516
2563
  async listModels() {
@@ -3282,17 +3329,24 @@
3282
3329
  /**
3283
3330
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3284
3331
  *
3285
- * @private as default `fetch` function used in Promptbook scrapers
3332
+ * @public exported from `@promptbook/core`
3286
3333
  */
3287
- const scraperFetch = async (url, init) => {
3334
+ const promptbookFetch = async (urlOrRequest, init) => {
3288
3335
  try {
3289
- return await fetch(url, init);
3336
+ return await fetch(urlOrRequest, init);
3290
3337
  }
3291
3338
  catch (error) {
3292
3339
  if (!(error instanceof Error)) {
3293
3340
  throw error;
3294
3341
  }
3295
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
3342
+ let url;
3343
+ if (typeof urlOrRequest === 'string') {
3344
+ url = urlOrRequest;
3345
+ }
3346
+ else if (urlOrRequest instanceof Request) {
3347
+ url = urlOrRequest.url;
3348
+ }
3349
+ throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
3296
3350
  Can not fetch "${url}"
3297
3351
 
3298
3352
  Fetch error:
@@ -3313,7 +3367,7 @@
3313
3367
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3314
3368
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
3315
3369
  var _a;
3316
- const { fetch = scraperFetch } = tools;
3370
+ const { fetch = promptbookFetch } = tools;
3317
3371
  const { knowledgeSourceContent } = knowledgeSource;
3318
3372
  let { name } = knowledgeSource;
3319
3373
  const { rootDirname = null,
@@ -3454,63 +3508,73 @@
3454
3508
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
3455
3509
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
3456
3510
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
3457
- let partialPieces = null;
3458
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3459
- const scrapers = arrayableToArray(tools.scrapers);
3460
- for (const scraper of scrapers) {
3461
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3462
- // <- TODO: [🦔] Implement mime-type wildcards
3463
- ) {
3464
- continue;
3465
- }
3466
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3467
- if (partialPiecesUnchecked !== null) {
3468
- partialPieces = [...partialPiecesUnchecked];
3469
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3470
- break;
3471
- }
3472
- console.warn(spaceTrim__default["default"]((block) => `
3473
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3511
+ try {
3512
+ let partialPieces = null;
3513
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
3514
+ const scrapers = arrayableToArray(tools.scrapers);
3515
+ for (const scraper of scrapers) {
3516
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
3517
+ // <- TODO: [🦔] Implement mime-type wildcards
3518
+ ) {
3519
+ continue;
3520
+ }
3521
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
3522
+ if (partialPiecesUnchecked !== null) {
3523
+ partialPieces = [...partialPiecesUnchecked];
3524
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
3525
+ break;
3526
+ }
3527
+ console.warn(spaceTrim__default["default"]((block) => `
3528
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
3474
3529
 
3475
- The source:
3476
- ${block(knowledgeSource.knowledgeSourceContent
3477
- .split('\n')
3478
- .map((line) => `> ${line}`)
3479
- .join('\n'))}
3530
+ The source:
3531
+ ${block(knowledgeSource.knowledgeSourceContent
3532
+ .split('\n')
3533
+ .map((line) => `> ${line}`)
3534
+ .join('\n'))}
3480
3535
 
3481
- ${block($registeredScrapersMessage(scrapers))}
3536
+ ${block($registeredScrapersMessage(scrapers))}
3482
3537
 
3483
3538
 
3484
- `));
3485
- }
3486
- if (partialPieces === null) {
3487
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
3488
- Cannot scrape knowledge
3539
+ `));
3540
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3541
+ }
3542
+ if (partialPieces === null) {
3543
+ throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
3544
+ Cannot scrape knowledge
3489
3545
 
3490
- The source:
3491
- > ${block(knowledgeSource.knowledgeSourceContent
3492
- .split('\n')
3493
- .map((line) => `> ${line}`)
3494
- .join('\n'))}
3546
+ The source:
3547
+ > ${block(knowledgeSource.knowledgeSourceContent
3548
+ .split('\n')
3549
+ .map((line) => `> ${line}`)
3550
+ .join('\n'))}
3495
3551
 
3496
- No scraper found for the mime type "${sourceHandler.mimeType}"
3552
+ No scraper found for the mime type "${sourceHandler.mimeType}"
3497
3553
 
3498
- ${block($registeredScrapersMessage(scrapers))}
3554
+ ${block($registeredScrapersMessage(scrapers))}
3499
3555
 
3500
3556
 
3501
- `));
3557
+ `));
3558
+ }
3559
+ const pieces = partialPieces.map((partialPiece) => ({
3560
+ ...partialPiece,
3561
+ sources: [
3562
+ {
3563
+ name: knowledgeSource.name,
3564
+ // line, column <- TODO: [☀]
3565
+ // <- TODO: [❎]
3566
+ },
3567
+ ],
3568
+ }));
3569
+ knowledgePreparedUnflatten[index] = pieces;
3570
+ }
3571
+ catch (error) {
3572
+ if (!(error instanceof Error)) {
3573
+ throw error;
3574
+ }
3575
+ console.warn(error);
3576
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3502
3577
  }
3503
- const pieces = partialPieces.map((partialPiece) => ({
3504
- ...partialPiece,
3505
- sources: [
3506
- {
3507
- name: knowledgeSource.name,
3508
- // line, column <- TODO: [☀]
3509
- // <- TODO: [❎]
3510
- },
3511
- ],
3512
- }));
3513
- knowledgePreparedUnflatten[index] = pieces;
3514
3578
  });
3515
3579
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
3516
3580
  return knowledgePrepared;
@@ -3928,7 +3992,7 @@
3928
3992
  if (parameterNames.has(subparameterName)) {
3929
3993
  parameterNames.delete(subparameterName);
3930
3994
  parameterNames.add(foreach.parameterName);
3931
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
3995
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
3932
3996
  }
3933
3997
  }
3934
3998
  }
@@ -5422,6 +5486,7 @@
5422
5486
 
5423
5487
  @see more at https://ptbk.io/prepare-pipeline
5424
5488
  `));
5489
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5425
5490
  }
5426
5491
  let runCount = 0;
5427
5492
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
@@ -5696,7 +5761,8 @@
5696
5761
  `));
5697
5762
  }
5698
5763
  console.warn(`No place where to put the section <!--${sectionName}-->, using the end of the file`);
5699
- // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
5764
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5765
+ // <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
5700
5766
  return spaceTrim.spaceTrim((block) => `
5701
5767
  ${block(content)}
5702
5768