@promptbook/node 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 +208 -113
  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 +2 -2
  49. package/umd/index.umd.js +208 -113
  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
package/README.md CHANGED
@@ -204,7 +204,7 @@ Each part of the book defines one of 3 circles:
204
204
 
205
205
  ### **What:** Workflows, Tasks and Parameters
206
206
 
207
- 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.
207
+ 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.
208
208
 
209
209
  **Related commands:**
210
210
 
@@ -314,6 +314,8 @@ The following glossary is used to clarify certain concepts:
314
314
 
315
315
 
316
316
 
317
+
318
+
317
319
  _Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
318
320
 
319
321
 
package/esm/index.es.js CHANGED
@@ -30,7 +30,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
30
30
  * @generated
31
31
  * @see https://github.com/webgptorg/promptbook
32
32
  */
33
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-1';
33
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
34
34
  /**
35
35
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
36
36
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -159,6 +159,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹‍♂️]
159
159
  */
160
160
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
161
161
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
162
+ // TODO: !!!!!! Just .promptbook dir, hardocode others
162
163
  /**
163
164
  * Where to store the temporary downloads
164
165
  *
@@ -175,6 +176,15 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
175
176
  * @public exported from `@promptbook/core`
176
177
  */
177
178
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
179
+ /*
180
+ TODO: [🌃]
181
+ /**
182
+ * Id of application for the wizzard when using remote server
183
+ *
184
+ * @public exported from `@promptbook/core`
185
+ * /
186
+ ex-port const WIZZARD_APP_ID: string_app_id = 'wizzard';
187
+ */
178
188
  /**
179
189
  * The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
180
190
  *
@@ -216,7 +226,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
216
226
  true);
217
227
  /**
218
228
  * Note: [💞] Ignore a discrepancy between file name and entity name
219
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
229
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
220
230
  */
221
231
 
222
232
  /**
@@ -1684,6 +1694,19 @@ class CsvFormatError extends AbstractFormatError {
1684
1694
  }
1685
1695
  }
1686
1696
 
1697
+ /**
1698
+ * AuthenticationError is thrown from login function which is dependency of remote server
1699
+ *
1700
+ * @public exported from `@promptbook/core`
1701
+ */
1702
+ class AuthenticationError extends Error {
1703
+ constructor(message) {
1704
+ super(message);
1705
+ this.name = 'AuthenticationError';
1706
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
1707
+ }
1708
+ }
1709
+
1687
1710
  /**
1688
1711
  * This error indicates that the pipeline collection cannot be propperly loaded
1689
1712
  *
@@ -1775,6 +1798,19 @@ class NotYetImplementedError extends Error {
1775
1798
  }
1776
1799
  }
1777
1800
 
1801
+ /**
1802
+ * Error thrown when a fetch request fails
1803
+ *
1804
+ * @public exported from `@promptbook/core`
1805
+ */
1806
+ class PromptbookFetchError extends Error {
1807
+ constructor(message) {
1808
+ super(message);
1809
+ this.name = 'PromptbookFetchError';
1810
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
1811
+ }
1812
+ }
1813
+
1778
1814
  /**
1779
1815
  * Index of all custom errors
1780
1816
  *
@@ -1812,6 +1848,8 @@ const COMMON_JAVASCRIPT_ERRORS = {
1812
1848
  TypeError,
1813
1849
  URIError,
1814
1850
  AggregateError,
1851
+ AuthenticationError,
1852
+ PromptbookFetchError,
1815
1853
  /*
1816
1854
  Note: Not widely supported
1817
1855
  > InternalError,
@@ -1873,6 +1911,7 @@ function assertsTaskSuccessful(executionResult) {
1873
1911
  const { isSuccessful, errors, warnings } = executionResult;
1874
1912
  for (const warning of warnings) {
1875
1913
  console.warn(warning.message);
1914
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
1876
1915
  }
1877
1916
  if (isSuccessful === true) {
1878
1917
  return;
@@ -2010,6 +2049,10 @@ function serializeError(error) {
2010
2049
 
2011
2050
  Cannot serialize error with name "${name}"
2012
2051
 
2052
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2053
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2054
+
2055
+
2013
2056
  ${block(stack || message)}
2014
2057
 
2015
2058
  `));
@@ -2097,30 +2140,42 @@ function valueToString(value) {
2097
2140
  }
2098
2141
  }
2099
2142
 
2143
+ /**
2144
+ * Represents the uncertain value
2145
+ *
2146
+ * @public exported from `@promptbook/core`
2147
+ */
2148
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2149
+ /**
2150
+ * Represents the uncertain value
2151
+ *
2152
+ * @public exported from `@promptbook/core`
2153
+ */
2154
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2100
2155
  /**
2101
2156
  * Represents the usage with no resources consumed
2102
2157
  *
2103
2158
  * @public exported from `@promptbook/core`
2104
2159
  */
2105
2160
  const ZERO_USAGE = $deepFreeze({
2106
- price: { value: 0 },
2161
+ price: ZERO_VALUE,
2107
2162
  input: {
2108
- tokensCount: { value: 0 },
2109
- charactersCount: { value: 0 },
2110
- wordsCount: { value: 0 },
2111
- sentencesCount: { value: 0 },
2112
- linesCount: { value: 0 },
2113
- paragraphsCount: { value: 0 },
2114
- pagesCount: { value: 0 },
2163
+ tokensCount: ZERO_VALUE,
2164
+ charactersCount: ZERO_VALUE,
2165
+ wordsCount: ZERO_VALUE,
2166
+ sentencesCount: ZERO_VALUE,
2167
+ linesCount: ZERO_VALUE,
2168
+ paragraphsCount: ZERO_VALUE,
2169
+ pagesCount: ZERO_VALUE,
2115
2170
  },
2116
2171
  output: {
2117
- tokensCount: { value: 0 },
2118
- charactersCount: { value: 0 },
2119
- wordsCount: { value: 0 },
2120
- sentencesCount: { value: 0 },
2121
- linesCount: { value: 0 },
2122
- paragraphsCount: { value: 0 },
2123
- pagesCount: { value: 0 },
2172
+ tokensCount: ZERO_VALUE,
2173
+ charactersCount: ZERO_VALUE,
2174
+ wordsCount: ZERO_VALUE,
2175
+ sentencesCount: ZERO_VALUE,
2176
+ linesCount: ZERO_VALUE,
2177
+ paragraphsCount: ZERO_VALUE,
2178
+ pagesCount: ZERO_VALUE,
2124
2179
  },
2125
2180
  });
2126
2181
  /**
@@ -2129,24 +2184,24 @@ const ZERO_USAGE = $deepFreeze({
2129
2184
  * @public exported from `@promptbook/core`
2130
2185
  */
2131
2186
  $deepFreeze({
2132
- price: { value: 0, isUncertain: true },
2187
+ price: UNCERTAIN_ZERO_VALUE,
2133
2188
  input: {
2134
- tokensCount: { value: 0, isUncertain: true },
2135
- charactersCount: { value: 0, isUncertain: true },
2136
- wordsCount: { value: 0, isUncertain: true },
2137
- sentencesCount: { value: 0, isUncertain: true },
2138
- linesCount: { value: 0, isUncertain: true },
2139
- paragraphsCount: { value: 0, isUncertain: true },
2140
- pagesCount: { value: 0, isUncertain: true },
2189
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2190
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2191
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2192
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2193
+ linesCount: UNCERTAIN_ZERO_VALUE,
2194
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2195
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2141
2196
  },
2142
2197
  output: {
2143
- tokensCount: { value: 0, isUncertain: true },
2144
- charactersCount: { value: 0, isUncertain: true },
2145
- wordsCount: { value: 0, isUncertain: true },
2146
- sentencesCount: { value: 0, isUncertain: true },
2147
- linesCount: { value: 0, isUncertain: true },
2148
- paragraphsCount: { value: 0, isUncertain: true },
2149
- pagesCount: { value: 0, isUncertain: true },
2198
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2199
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2200
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2201
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2202
+ linesCount: UNCERTAIN_ZERO_VALUE,
2203
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2204
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2150
2205
  },
2151
2206
  });
2152
2207
  /**
@@ -2317,7 +2372,7 @@ function extractParameterNamesFromTask(task) {
2317
2372
  if (parameterNames.has(subparameterName)) {
2318
2373
  parameterNames.delete(subparameterName);
2319
2374
  parameterNames.add(foreach.parameterName);
2320
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
2375
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
2321
2376
  }
2322
2377
  }
2323
2378
  }
@@ -2811,6 +2866,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
2811
2866
  `);
2812
2867
  // TODO: [🟥] Detect browser / node and make it colorfull
2813
2868
  console.warn(warningMessage);
2869
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2814
2870
  /*
2815
2871
  return {
2816
2872
  async listModels() {
@@ -4400,6 +4456,7 @@ function createPipelineExecutor(options) {
4400
4456
 
4401
4457
  @see more at https://ptbk.io/prepare-pipeline
4402
4458
  `));
4459
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
4403
4460
  }
4404
4461
  let runCount = 0;
4405
4462
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
@@ -5004,17 +5061,24 @@ function titleToName(value) {
5004
5061
  /**
5005
5062
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
5006
5063
  *
5007
- * @private as default `fetch` function used in Promptbook scrapers
5064
+ * @public exported from `@promptbook/core`
5008
5065
  */
5009
- const scraperFetch = async (url, init) => {
5066
+ const promptbookFetch = async (urlOrRequest, init) => {
5010
5067
  try {
5011
- return await fetch(url, init);
5068
+ return await fetch(urlOrRequest, init);
5012
5069
  }
5013
5070
  catch (error) {
5014
5071
  if (!(error instanceof Error)) {
5015
5072
  throw error;
5016
5073
  }
5017
- throw new KnowledgeScrapeError(spaceTrim((block) => `
5074
+ let url;
5075
+ if (typeof urlOrRequest === 'string') {
5076
+ url = urlOrRequest;
5077
+ }
5078
+ else if (urlOrRequest instanceof Request) {
5079
+ url = urlOrRequest.url;
5080
+ }
5081
+ throw new PromptbookFetchError(spaceTrim((block) => `
5018
5082
  Can not fetch "${url}"
5019
5083
 
5020
5084
  Fetch error:
@@ -5035,7 +5099,7 @@ const scraperFetch = async (url, init) => {
5035
5099
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5036
5100
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
5037
5101
  var _a;
5038
- const { fetch = scraperFetch } = tools;
5102
+ const { fetch = promptbookFetch } = tools;
5039
5103
  const { knowledgeSourceContent } = knowledgeSource;
5040
5104
  let { name } = knowledgeSource;
5041
5105
  const { rootDirname = null,
@@ -5176,63 +5240,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
5176
5240
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
5177
5241
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
5178
5242
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
5179
- let partialPieces = null;
5180
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
5181
- const scrapers = arrayableToArray(tools.scrapers);
5182
- for (const scraper of scrapers) {
5183
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
5184
- // <- TODO: [🦔] Implement mime-type wildcards
5185
- ) {
5186
- continue;
5187
- }
5188
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
5189
- if (partialPiecesUnchecked !== null) {
5190
- partialPieces = [...partialPiecesUnchecked];
5191
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
5192
- break;
5193
- }
5194
- console.warn(spaceTrim((block) => `
5195
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
5243
+ try {
5244
+ let partialPieces = null;
5245
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
5246
+ const scrapers = arrayableToArray(tools.scrapers);
5247
+ for (const scraper of scrapers) {
5248
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
5249
+ // <- TODO: [🦔] Implement mime-type wildcards
5250
+ ) {
5251
+ continue;
5252
+ }
5253
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
5254
+ if (partialPiecesUnchecked !== null) {
5255
+ partialPieces = [...partialPiecesUnchecked];
5256
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
5257
+ break;
5258
+ }
5259
+ console.warn(spaceTrim((block) => `
5260
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
5196
5261
 
5197
- The source:
5198
- ${block(knowledgeSource.knowledgeSourceContent
5199
- .split('\n')
5200
- .map((line) => `> ${line}`)
5201
- .join('\n'))}
5262
+ The source:
5263
+ ${block(knowledgeSource.knowledgeSourceContent
5264
+ .split('\n')
5265
+ .map((line) => `> ${line}`)
5266
+ .join('\n'))}
5202
5267
 
5203
- ${block($registeredScrapersMessage(scrapers))}
5268
+ ${block($registeredScrapersMessage(scrapers))}
5204
5269
 
5205
5270
 
5206
- `));
5207
- }
5208
- if (partialPieces === null) {
5209
- throw new KnowledgeScrapeError(spaceTrim((block) => `
5210
- Cannot scrape knowledge
5271
+ `));
5272
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5273
+ }
5274
+ if (partialPieces === null) {
5275
+ throw new KnowledgeScrapeError(spaceTrim((block) => `
5276
+ Cannot scrape knowledge
5211
5277
 
5212
- The source:
5213
- > ${block(knowledgeSource.knowledgeSourceContent
5214
- .split('\n')
5215
- .map((line) => `> ${line}`)
5216
- .join('\n'))}
5278
+ The source:
5279
+ > ${block(knowledgeSource.knowledgeSourceContent
5280
+ .split('\n')
5281
+ .map((line) => `> ${line}`)
5282
+ .join('\n'))}
5217
5283
 
5218
- No scraper found for the mime type "${sourceHandler.mimeType}"
5284
+ No scraper found for the mime type "${sourceHandler.mimeType}"
5219
5285
 
5220
- ${block($registeredScrapersMessage(scrapers))}
5286
+ ${block($registeredScrapersMessage(scrapers))}
5221
5287
 
5222
5288
 
5223
- `));
5289
+ `));
5290
+ }
5291
+ const pieces = partialPieces.map((partialPiece) => ({
5292
+ ...partialPiece,
5293
+ sources: [
5294
+ {
5295
+ name: knowledgeSource.name,
5296
+ // line, column <- TODO: [☀]
5297
+ // <- TODO: [❎]
5298
+ },
5299
+ ],
5300
+ }));
5301
+ knowledgePreparedUnflatten[index] = pieces;
5302
+ }
5303
+ catch (error) {
5304
+ if (!(error instanceof Error)) {
5305
+ throw error;
5306
+ }
5307
+ console.warn(error);
5308
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5224
5309
  }
5225
- const pieces = partialPieces.map((partialPiece) => ({
5226
- ...partialPiece,
5227
- sources: [
5228
- {
5229
- name: knowledgeSource.name,
5230
- // line, column <- TODO: [☀]
5231
- // <- TODO: [❎]
5232
- },
5233
- ],
5234
- }));
5235
- knowledgePreparedUnflatten[index] = pieces;
5236
5310
  });
5237
5311
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
5238
5312
  return knowledgePrepared;
@@ -7057,7 +7131,8 @@ const modelCommandParser = {
7057
7131
  if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
7058
7132
  if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
7059
7133
  console.warn(`Multiple commands \`MODEL ${command.key} ${command.value}\` in the pipeline head`);
7060
- // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
7134
+ // <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
7135
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
7061
7136
  }
7062
7137
  else {
7063
7138
  throw new ParseError(spaceTrim(`
@@ -7089,6 +7164,7 @@ const modelCommandParser = {
7089
7164
  modelVariant: 'VARIANT',
7090
7165
  maxTokens: '???',
7091
7166
  }[command.key]} ${command.value}\` in the task "${$taskJson.title || $taskJson.name}"`);
7167
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
7092
7168
  }
7093
7169
  else {
7094
7170
  throw new ParseError(spaceTrim(`
@@ -7368,15 +7444,15 @@ function $applyToTaskJson(command, $taskJson, $pipelineJson) {
7368
7444
  }
7369
7445
  console.warn(spaceTrim(`
7370
7446
 
7371
- Persona "${personaName}" is defined multiple times with different description:
7447
+ Persona "${personaName}" is defined multiple times with different description:
7372
7448
 
7373
- First definition:
7374
- ${persona.description}
7449
+ First definition:
7450
+ ${persona.description}
7375
7451
 
7376
- Second definition:
7377
- ${personaDescription}
7452
+ Second definition:
7453
+ ${personaDescription}
7378
7454
 
7379
- `));
7455
+ `));
7380
7456
  persona.description += spaceTrim('\n\n' + personaDescription);
7381
7457
  }
7382
7458
 
@@ -9012,6 +9088,7 @@ function $execCommand(options) {
9012
9088
  }
9013
9089
  else {
9014
9090
  console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
9091
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9015
9092
  resolve('Command exceeded time limit');
9016
9093
  }
9017
9094
  });
@@ -9037,6 +9114,7 @@ function $execCommand(options) {
9037
9114
  output.push(stderr.toString());
9038
9115
  if (isVerbose && stderr.toString().trim()) {
9039
9116
  console.warn(stderr.toString());
9117
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9040
9118
  }
9041
9119
  });
9042
9120
  const finishWithCode = (code) => {
@@ -9048,6 +9126,7 @@ function $execCommand(options) {
9048
9126
  else {
9049
9127
  if (isVerbose) {
9050
9128
  console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
9129
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9051
9130
  }
9052
9131
  resolve(spaceTrim$1(output.join('\n')));
9053
9132
  }
@@ -9069,6 +9148,7 @@ function $execCommand(options) {
9069
9148
  else {
9070
9149
  if (isVerbose) {
9071
9150
  console.warn(error);
9151
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9072
9152
  }
9073
9153
  resolve(spaceTrim$1(output.join('\n')));
9074
9154
  }
@@ -9499,21 +9579,15 @@ function $registeredLlmToolsMessage() {
9499
9579
  */
9500
9580
 
9501
9581
  /**
9502
- * @@@
9503
- *
9504
- * @@@ .env
9582
+ * Provides the path to the `.env` file
9505
9583
  *
9506
- * It looks for environment variables:
9507
- * - `process.env.OPENAI_API_KEY`
9508
- * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9509
- * - ...
9584
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
9510
9585
  *
9511
- * @returns @@@
9512
- * @public exported from `@promptbook/node`
9586
+ * @private within the repository - for CLI utils
9513
9587
  */
9514
- async function $provideLlmToolsConfigurationFromEnv() {
9588
+ async function $provideEnvFilename() {
9515
9589
  if (!$isRunningInNode()) {
9516
- throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9590
+ throw new EnvironmentMismatchError('Function `$provideEnvFilename` works only in Node.js environment');
9517
9591
  }
9518
9592
  const envFilePatterns = [
9519
9593
  '.env',
@@ -9533,8 +9607,7 @@ async function $provideLlmToolsConfigurationFromEnv() {
9533
9607
  const envFilename = join(rootDirname, pattern);
9534
9608
  if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
9535
9609
  $setUsedEnvFilename(envFilename);
9536
- dotenv.config({ path: envFilename });
9537
- break up_to_root;
9610
+ return envFilename;
9538
9611
  }
9539
9612
  }
9540
9613
  if (isRootPath(rootDirname)) {
@@ -9543,6 +9616,34 @@ async function $provideLlmToolsConfigurationFromEnv() {
9543
9616
  // Note: If the directory does not exist, try the parent directory
9544
9617
  rootDirname = join(rootDirname, '..');
9545
9618
  }
9619
+ return null;
9620
+ }
9621
+ /**
9622
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9623
+ */
9624
+
9625
+ /**
9626
+ * @@@
9627
+ *
9628
+ * @@@ .env
9629
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
9630
+ *
9631
+ * It looks for environment variables:
9632
+ * - `process.env.OPENAI_API_KEY`
9633
+ * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9634
+ * - ...
9635
+ *
9636
+ * @returns @@@
9637
+ * @public exported from `@promptbook/node`
9638
+ */
9639
+ async function $provideLlmToolsConfigurationFromEnv() {
9640
+ if (!$isRunningInNode()) {
9641
+ throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9642
+ }
9643
+ const envFilepath = await $provideEnvFilename();
9644
+ if (envFilepath !== null) {
9645
+ dotenv.config({ path: envFilepath });
9646
+ }
9546
9647
  const llmToolsConfiguration = $llmToolsMetadataRegister
9547
9648
  .list()
9548
9649
  .map((metadata) => metadata.createConfigurationFromEnv(process.env))
@@ -9550,15 +9651,8 @@ async function $provideLlmToolsConfigurationFromEnv() {
9550
9651
  return llmToolsConfiguration;
9551
9652
  }
9552
9653
  /**
9553
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
9554
- * TODO: Add Azure OpenAI
9555
- * TODO: [🧠][🍛]
9556
- * TODO: [🧠] Is there some meaningfull way how to test this util
9557
9654
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9558
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
9559
- * TODO: This should be maybe not under `_common` but under `utils`
9560
- * TODO: [🧠][⚛] Maybe pass env as argument
9561
- * TODO: [®] DRY Register logic */
9655
+ */
9562
9656
 
9563
9657
  /**
9564
9658
  * @@@
@@ -9617,6 +9711,7 @@ function createLlmToolsFromConfiguration(configuration, options = {}) {
9617
9711
  * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
9618
9712
  *
9619
9713
  * @@@ .env
9714
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
9620
9715
  *
9621
9716
  * It looks for environment variables:
9622
9717
  * - `process.env.OPENAI_API_KEY`