@promptbook/node 0.88.0 → 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 +7 -1
  2. package/esm/index.es.js +218 -116
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +18 -6
  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 -10
  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 +9 -2
  29. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
  30. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
  31. package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
  32. package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
  33. package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
  34. package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
  35. package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
  36. package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
  37. package/esm/typings/src/playground/playground.d.ts +5 -0
  38. package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
  39. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +5 -4
  40. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  41. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  42. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  43. package/esm/typings/src/remote-server/startRemoteServer.d.ts +2 -2
  44. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
  45. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +88 -6
  46. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  47. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +37 -0
  48. package/esm/typings/src/types/typeAliases.d.ts +8 -2
  49. package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
  50. package/package.json +2 -2
  51. package/umd/index.umd.js +218 -116
  52. package/umd/index.umd.js.map +1 -1
package/umd/index.umd.js CHANGED
@@ -46,7 +46,7 @@
46
46
  * @generated
47
47
  * @see https://github.com/webgptorg/promptbook
48
48
  */
49
- const PROMPTBOOK_ENGINE_VERSION = '0.88.0';
49
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
50
50
  /**
51
51
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
52
52
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -175,6 +175,7 @@
175
175
  */
176
176
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
177
177
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
178
+ // TODO: !!!!!! Just .promptbook dir, hardocode others
178
179
  /**
179
180
  * Where to store the temporary downloads
180
181
  *
@@ -191,6 +192,15 @@
191
192
  * @public exported from `@promptbook/core`
192
193
  */
193
194
  const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
195
+ /*
196
+ TODO: [🌃]
197
+ /**
198
+ * Id of application for the wizzard when using remote server
199
+ *
200
+ * @public exported from `@promptbook/core`
201
+ * /
202
+ ex-port const WIZZARD_APP_ID: string_app_id = 'wizzard';
203
+ */
194
204
  /**
195
205
  * The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
196
206
  *
@@ -232,7 +242,7 @@
232
242
  true);
233
243
  /**
234
244
  * Note: [💞] Ignore a discrepancy between file name and entity name
235
- * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
245
+ * TODO: [🧠][🧜‍♂️] Maybe join remoteServerUrl and path into single value
236
246
  */
237
247
 
238
248
  /**
@@ -1700,6 +1710,19 @@
1700
1710
  }
1701
1711
  }
1702
1712
 
1713
+ /**
1714
+ * AuthenticationError is thrown from login function which is dependency of remote server
1715
+ *
1716
+ * @public exported from `@promptbook/core`
1717
+ */
1718
+ class AuthenticationError extends Error {
1719
+ constructor(message) {
1720
+ super(message);
1721
+ this.name = 'AuthenticationError';
1722
+ Object.setPrototypeOf(this, AuthenticationError.prototype);
1723
+ }
1724
+ }
1725
+
1703
1726
  /**
1704
1727
  * This error indicates that the pipeline collection cannot be propperly loaded
1705
1728
  *
@@ -1791,6 +1814,19 @@
1791
1814
  }
1792
1815
  }
1793
1816
 
1817
+ /**
1818
+ * Error thrown when a fetch request fails
1819
+ *
1820
+ * @public exported from `@promptbook/core`
1821
+ */
1822
+ class PromptbookFetchError extends Error {
1823
+ constructor(message) {
1824
+ super(message);
1825
+ this.name = 'PromptbookFetchError';
1826
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
1827
+ }
1828
+ }
1829
+
1794
1830
  /**
1795
1831
  * Index of all custom errors
1796
1832
  *
@@ -1828,6 +1864,8 @@
1828
1864
  TypeError,
1829
1865
  URIError,
1830
1866
  AggregateError,
1867
+ AuthenticationError,
1868
+ PromptbookFetchError,
1831
1869
  /*
1832
1870
  Note: Not widely supported
1833
1871
  > InternalError,
@@ -1889,6 +1927,7 @@
1889
1927
  const { isSuccessful, errors, warnings } = executionResult;
1890
1928
  for (const warning of warnings) {
1891
1929
  console.warn(warning.message);
1930
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
1892
1931
  }
1893
1932
  if (isSuccessful === true) {
1894
1933
  return;
@@ -2026,6 +2065,10 @@
2026
2065
 
2027
2066
  Cannot serialize error with name "${name}"
2028
2067
 
2068
+ Authors of Promptbook probably forgot to add this error into the list of errors:
2069
+ https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
2070
+
2071
+
2029
2072
  ${block(stack || message)}
2030
2073
 
2031
2074
  `));
@@ -2113,30 +2156,42 @@
2113
2156
  }
2114
2157
  }
2115
2158
 
2159
+ /**
2160
+ * Represents the uncertain value
2161
+ *
2162
+ * @public exported from `@promptbook/core`
2163
+ */
2164
+ const ZERO_VALUE = $deepFreeze({ value: 0 });
2165
+ /**
2166
+ * Represents the uncertain value
2167
+ *
2168
+ * @public exported from `@promptbook/core`
2169
+ */
2170
+ const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
2116
2171
  /**
2117
2172
  * Represents the usage with no resources consumed
2118
2173
  *
2119
2174
  * @public exported from `@promptbook/core`
2120
2175
  */
2121
2176
  const ZERO_USAGE = $deepFreeze({
2122
- price: { value: 0 },
2177
+ price: ZERO_VALUE,
2123
2178
  input: {
2124
- tokensCount: { value: 0 },
2125
- charactersCount: { value: 0 },
2126
- wordsCount: { value: 0 },
2127
- sentencesCount: { value: 0 },
2128
- linesCount: { value: 0 },
2129
- paragraphsCount: { value: 0 },
2130
- pagesCount: { value: 0 },
2179
+ tokensCount: ZERO_VALUE,
2180
+ charactersCount: ZERO_VALUE,
2181
+ wordsCount: ZERO_VALUE,
2182
+ sentencesCount: ZERO_VALUE,
2183
+ linesCount: ZERO_VALUE,
2184
+ paragraphsCount: ZERO_VALUE,
2185
+ pagesCount: ZERO_VALUE,
2131
2186
  },
2132
2187
  output: {
2133
- tokensCount: { value: 0 },
2134
- charactersCount: { value: 0 },
2135
- wordsCount: { value: 0 },
2136
- sentencesCount: { value: 0 },
2137
- linesCount: { value: 0 },
2138
- paragraphsCount: { value: 0 },
2139
- pagesCount: { value: 0 },
2188
+ tokensCount: ZERO_VALUE,
2189
+ charactersCount: ZERO_VALUE,
2190
+ wordsCount: ZERO_VALUE,
2191
+ sentencesCount: ZERO_VALUE,
2192
+ linesCount: ZERO_VALUE,
2193
+ paragraphsCount: ZERO_VALUE,
2194
+ pagesCount: ZERO_VALUE,
2140
2195
  },
2141
2196
  });
2142
2197
  /**
@@ -2145,24 +2200,24 @@
2145
2200
  * @public exported from `@promptbook/core`
2146
2201
  */
2147
2202
  $deepFreeze({
2148
- price: { value: 0, isUncertain: true },
2203
+ price: UNCERTAIN_ZERO_VALUE,
2149
2204
  input: {
2150
- tokensCount: { value: 0, isUncertain: true },
2151
- charactersCount: { value: 0, isUncertain: true },
2152
- wordsCount: { value: 0, isUncertain: true },
2153
- sentencesCount: { value: 0, isUncertain: true },
2154
- linesCount: { value: 0, isUncertain: true },
2155
- paragraphsCount: { value: 0, isUncertain: true },
2156
- pagesCount: { value: 0, isUncertain: true },
2205
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2206
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2207
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2208
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2209
+ linesCount: UNCERTAIN_ZERO_VALUE,
2210
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2211
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2157
2212
  },
2158
2213
  output: {
2159
- tokensCount: { value: 0, isUncertain: true },
2160
- charactersCount: { value: 0, isUncertain: true },
2161
- wordsCount: { value: 0, isUncertain: true },
2162
- sentencesCount: { value: 0, isUncertain: true },
2163
- linesCount: { value: 0, isUncertain: true },
2164
- paragraphsCount: { value: 0, isUncertain: true },
2165
- pagesCount: { value: 0, isUncertain: true },
2214
+ tokensCount: UNCERTAIN_ZERO_VALUE,
2215
+ charactersCount: UNCERTAIN_ZERO_VALUE,
2216
+ wordsCount: UNCERTAIN_ZERO_VALUE,
2217
+ sentencesCount: UNCERTAIN_ZERO_VALUE,
2218
+ linesCount: UNCERTAIN_ZERO_VALUE,
2219
+ paragraphsCount: UNCERTAIN_ZERO_VALUE,
2220
+ pagesCount: UNCERTAIN_ZERO_VALUE,
2166
2221
  },
2167
2222
  });
2168
2223
  /**
@@ -2333,7 +2388,7 @@
2333
2388
  if (parameterNames.has(subparameterName)) {
2334
2389
  parameterNames.delete(subparameterName);
2335
2390
  parameterNames.add(foreach.parameterName);
2336
- // <- TODO: [🚎] Warn/logic error when `subparameterName` not used
2391
+ // <- TODO: [🏮] Warn/logic error when `subparameterName` not used
2337
2392
  }
2338
2393
  }
2339
2394
  }
@@ -2827,6 +2882,7 @@
2827
2882
  `);
2828
2883
  // TODO: [🟥] Detect browser / node and make it colorfull
2829
2884
  console.warn(warningMessage);
2885
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
2830
2886
  /*
2831
2887
  return {
2832
2888
  async listModels() {
@@ -4416,6 +4472,7 @@
4416
4472
 
4417
4473
  @see more at https://ptbk.io/prepare-pipeline
4418
4474
  `));
4475
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
4419
4476
  }
4420
4477
  let runCount = 0;
4421
4478
  const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
@@ -4492,8 +4549,9 @@
4492
4549
  * @returns LLM tools with same functionality with added total cost counting
4493
4550
  * @public exported from `@promptbook/core`
4494
4551
  */
4495
- function countTotalUsage(llmTools) {
4552
+ function countUsage(llmTools) {
4496
4553
  let totalUsage = ZERO_USAGE;
4554
+ const spending = new rxjs.Subject();
4497
4555
  const proxyTools = {
4498
4556
  get title() {
4499
4557
  // TODO: [🧠] Maybe put here some suffix
@@ -4503,12 +4561,15 @@
4503
4561
  // TODO: [🧠] Maybe put here some suffix
4504
4562
  return llmTools.description;
4505
4563
  },
4506
- async checkConfiguration() {
4564
+ checkConfiguration() {
4507
4565
  return /* not await */ llmTools.checkConfiguration();
4508
4566
  },
4509
4567
  listModels() {
4510
4568
  return /* not await */ llmTools.listModels();
4511
4569
  },
4570
+ spending() {
4571
+ return spending.asObservable();
4572
+ },
4512
4573
  getTotalUsage() {
4513
4574
  // <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
4514
4575
  return totalUsage;
@@ -4519,6 +4580,7 @@
4519
4580
  // console.info('[🚕] callChatModel through countTotalUsage');
4520
4581
  const promptResult = await llmTools.callChatModel(prompt);
4521
4582
  totalUsage = addUsage(totalUsage, promptResult.usage);
4583
+ spending.next(promptResult.usage);
4522
4584
  return promptResult;
4523
4585
  };
4524
4586
  }
@@ -4527,6 +4589,7 @@
4527
4589
  // console.info('[🚕] callCompletionModel through countTotalUsage');
4528
4590
  const promptResult = await llmTools.callCompletionModel(prompt);
4529
4591
  totalUsage = addUsage(totalUsage, promptResult.usage);
4592
+ spending.next(promptResult.usage);
4530
4593
  return promptResult;
4531
4594
  };
4532
4595
  }
@@ -4535,6 +4598,7 @@
4535
4598
  // console.info('[🚕] callEmbeddingModel through countTotalUsage');
4536
4599
  const promptResult = await llmTools.callEmbeddingModel(prompt);
4537
4600
  totalUsage = addUsage(totalUsage, promptResult.usage);
4601
+ spending.next(promptResult.usage);
4538
4602
  return promptResult;
4539
4603
  };
4540
4604
  }
@@ -5013,17 +5077,24 @@
5013
5077
  /**
5014
5078
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
5015
5079
  *
5016
- * @private as default `fetch` function used in Promptbook scrapers
5080
+ * @public exported from `@promptbook/core`
5017
5081
  */
5018
- const scraperFetch = async (url, init) => {
5082
+ const promptbookFetch = async (urlOrRequest, init) => {
5019
5083
  try {
5020
- return await fetch(url, init);
5084
+ return await fetch(urlOrRequest, init);
5021
5085
  }
5022
5086
  catch (error) {
5023
5087
  if (!(error instanceof Error)) {
5024
5088
  throw error;
5025
5089
  }
5026
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
5090
+ let url;
5091
+ if (typeof urlOrRequest === 'string') {
5092
+ url = urlOrRequest;
5093
+ }
5094
+ else if (urlOrRequest instanceof Request) {
5095
+ url = urlOrRequest.url;
5096
+ }
5097
+ throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
5027
5098
  Can not fetch "${url}"
5028
5099
 
5029
5100
  Fetch error:
@@ -5044,7 +5115,7 @@
5044
5115
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5045
5116
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
5046
5117
  var _a;
5047
- const { fetch = scraperFetch } = tools;
5118
+ const { fetch = promptbookFetch } = tools;
5048
5119
  const { knowledgeSourceContent } = knowledgeSource;
5049
5120
  let { name } = knowledgeSource;
5050
5121
  const { rootDirname = null,
@@ -5185,63 +5256,73 @@
5185
5256
  const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
5186
5257
  const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
5187
5258
  await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
5188
- let partialPieces = null;
5189
- const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
5190
- const scrapers = arrayableToArray(tools.scrapers);
5191
- for (const scraper of scrapers) {
5192
- if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
5193
- // <- TODO: [🦔] Implement mime-type wildcards
5194
- ) {
5195
- continue;
5196
- }
5197
- const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
5198
- if (partialPiecesUnchecked !== null) {
5199
- partialPieces = [...partialPiecesUnchecked];
5200
- // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
5201
- break;
5202
- }
5203
- console.warn(spaceTrim__default["default"]((block) => `
5204
- Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
5259
+ try {
5260
+ let partialPieces = null;
5261
+ const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
5262
+ const scrapers = arrayableToArray(tools.scrapers);
5263
+ for (const scraper of scrapers) {
5264
+ if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
5265
+ // <- TODO: [🦔] Implement mime-type wildcards
5266
+ ) {
5267
+ continue;
5268
+ }
5269
+ const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
5270
+ if (partialPiecesUnchecked !== null) {
5271
+ partialPieces = [...partialPiecesUnchecked];
5272
+ // <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
5273
+ break;
5274
+ }
5275
+ console.warn(spaceTrim__default["default"]((block) => `
5276
+ Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
5205
5277
 
5206
- The source:
5207
- ${block(knowledgeSource.knowledgeSourceContent
5208
- .split('\n')
5209
- .map((line) => `> ${line}`)
5210
- .join('\n'))}
5278
+ The source:
5279
+ ${block(knowledgeSource.knowledgeSourceContent
5280
+ .split('\n')
5281
+ .map((line) => `> ${line}`)
5282
+ .join('\n'))}
5211
5283
 
5212
- ${block($registeredScrapersMessage(scrapers))}
5284
+ ${block($registeredScrapersMessage(scrapers))}
5213
5285
 
5214
5286
 
5215
- `));
5216
- }
5217
- if (partialPieces === null) {
5218
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
5219
- Cannot scrape knowledge
5287
+ `));
5288
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5289
+ }
5290
+ if (partialPieces === null) {
5291
+ throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
5292
+ Cannot scrape knowledge
5220
5293
 
5221
- The source:
5222
- > ${block(knowledgeSource.knowledgeSourceContent
5223
- .split('\n')
5224
- .map((line) => `> ${line}`)
5225
- .join('\n'))}
5294
+ The source:
5295
+ > ${block(knowledgeSource.knowledgeSourceContent
5296
+ .split('\n')
5297
+ .map((line) => `> ${line}`)
5298
+ .join('\n'))}
5226
5299
 
5227
- No scraper found for the mime type "${sourceHandler.mimeType}"
5300
+ No scraper found for the mime type "${sourceHandler.mimeType}"
5228
5301
 
5229
- ${block($registeredScrapersMessage(scrapers))}
5302
+ ${block($registeredScrapersMessage(scrapers))}
5230
5303
 
5231
5304
 
5232
- `));
5305
+ `));
5306
+ }
5307
+ const pieces = partialPieces.map((partialPiece) => ({
5308
+ ...partialPiece,
5309
+ sources: [
5310
+ {
5311
+ name: knowledgeSource.name,
5312
+ // line, column <- TODO: [☀]
5313
+ // <- TODO: [❎]
5314
+ },
5315
+ ],
5316
+ }));
5317
+ knowledgePreparedUnflatten[index] = pieces;
5318
+ }
5319
+ catch (error) {
5320
+ if (!(error instanceof Error)) {
5321
+ throw error;
5322
+ }
5323
+ console.warn(error);
5324
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5233
5325
  }
5234
- const pieces = partialPieces.map((partialPiece) => ({
5235
- ...partialPiece,
5236
- sources: [
5237
- {
5238
- name: knowledgeSource.name,
5239
- // line, column <- TODO: [☀]
5240
- // <- TODO: [❎]
5241
- },
5242
- ],
5243
- }));
5244
- knowledgePreparedUnflatten[index] = pieces;
5245
5326
  });
5246
5327
  const knowledgePrepared = knowledgePreparedUnflatten.flat();
5247
5328
  return knowledgePrepared;
@@ -5347,7 +5428,7 @@
5347
5428
  // TODO: [🚐] Make arrayable LLMs -> single LLM DRY
5348
5429
  const _llms = arrayableToArray(tools.llm);
5349
5430
  const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
5350
- const llmToolsWithUsage = countTotalUsage(llmTools);
5431
+ const llmToolsWithUsage = countUsage(llmTools);
5351
5432
  // <- TODO: [🌯]
5352
5433
  /*
5353
5434
  TODO: [🧠][🪑][🔃] Should this be done or not
@@ -7066,7 +7147,8 @@
7066
7147
  if ($pipelineJson.defaultModelRequirements[command.key] !== undefined) {
7067
7148
  if ($pipelineJson.defaultModelRequirements[command.key] === command.value) {
7068
7149
  console.warn(`Multiple commands \`MODEL ${command.key} ${command.value}\` in the pipeline head`);
7069
- // <- TODO: [🚎][💩] Some better way how to get warnings from pipeline parsing / logic
7150
+ // <- TODO: [🏮] Some better way how to get warnings from pipeline parsing / logic
7151
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
7070
7152
  }
7071
7153
  else {
7072
7154
  throw new ParseError(spaceTrim__default["default"](`
@@ -7098,6 +7180,7 @@
7098
7180
  modelVariant: 'VARIANT',
7099
7181
  maxTokens: '???',
7100
7182
  }[command.key]} ${command.value}\` in the task "${$taskJson.title || $taskJson.name}"`);
7183
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
7101
7184
  }
7102
7185
  else {
7103
7186
  throw new ParseError(spaceTrim__default["default"](`
@@ -7377,15 +7460,15 @@
7377
7460
  }
7378
7461
  console.warn(spaceTrim__default["default"](`
7379
7462
 
7380
- Persona "${personaName}" is defined multiple times with different description:
7463
+ Persona "${personaName}" is defined multiple times with different description:
7381
7464
 
7382
- First definition:
7383
- ${persona.description}
7465
+ First definition:
7466
+ ${persona.description}
7384
7467
 
7385
- Second definition:
7386
- ${personaDescription}
7468
+ Second definition:
7469
+ ${personaDescription}
7387
7470
 
7388
- `));
7471
+ `));
7389
7472
  persona.description += spaceTrim__default["default"]('\n\n' + personaDescription);
7390
7473
  }
7391
7474
 
@@ -9021,6 +9104,7 @@
9021
9104
  }
9022
9105
  else {
9023
9106
  console.warn(`Command "${humanReadableCommand}" exceeded time limit of ${timeout}ms but continues running`);
9107
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9024
9108
  resolve('Command exceeded time limit');
9025
9109
  }
9026
9110
  });
@@ -9046,6 +9130,7 @@
9046
9130
  output.push(stderr.toString());
9047
9131
  if (isVerbose && stderr.toString().trim()) {
9048
9132
  console.warn(stderr.toString());
9133
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9049
9134
  }
9050
9135
  });
9051
9136
  const finishWithCode = (code) => {
@@ -9057,6 +9142,7 @@
9057
9142
  else {
9058
9143
  if (isVerbose) {
9059
9144
  console.warn(`Command "${humanReadableCommand}" exited with code ${code}`);
9145
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9060
9146
  }
9061
9147
  resolve(spaceTrim.spaceTrim(output.join('\n')));
9062
9148
  }
@@ -9078,6 +9164,7 @@
9078
9164
  else {
9079
9165
  if (isVerbose) {
9080
9166
  console.warn(error);
9167
+ // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
9081
9168
  }
9082
9169
  resolve(spaceTrim.spaceTrim(output.join('\n')));
9083
9170
  }
@@ -9508,21 +9595,15 @@
9508
9595
  */
9509
9596
 
9510
9597
  /**
9511
- * @@@
9512
- *
9513
- * @@@ .env
9598
+ * Provides the path to the `.env` file
9514
9599
  *
9515
- * It looks for environment variables:
9516
- * - `process.env.OPENAI_API_KEY`
9517
- * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9518
- * - ...
9600
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
9519
9601
  *
9520
- * @returns @@@
9521
- * @public exported from `@promptbook/node`
9602
+ * @private within the repository - for CLI utils
9522
9603
  */
9523
- async function $provideLlmToolsConfigurationFromEnv() {
9604
+ async function $provideEnvFilename() {
9524
9605
  if (!$isRunningInNode()) {
9525
- throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9606
+ throw new EnvironmentMismatchError('Function `$provideEnvFilename` works only in Node.js environment');
9526
9607
  }
9527
9608
  const envFilePatterns = [
9528
9609
  '.env',
@@ -9542,8 +9623,7 @@
9542
9623
  const envFilename = path.join(rootDirname, pattern);
9543
9624
  if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
9544
9625
  $setUsedEnvFilename(envFilename);
9545
- dotenv__namespace.config({ path: envFilename });
9546
- break up_to_root;
9626
+ return envFilename;
9547
9627
  }
9548
9628
  }
9549
9629
  if (isRootPath(rootDirname)) {
@@ -9552,6 +9632,34 @@
9552
9632
  // Note: If the directory does not exist, try the parent directory
9553
9633
  rootDirname = path.join(rootDirname, '..');
9554
9634
  }
9635
+ return null;
9636
+ }
9637
+ /**
9638
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9639
+ */
9640
+
9641
+ /**
9642
+ * @@@
9643
+ *
9644
+ * @@@ .env
9645
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
9646
+ *
9647
+ * It looks for environment variables:
9648
+ * - `process.env.OPENAI_API_KEY`
9649
+ * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9650
+ * - ...
9651
+ *
9652
+ * @returns @@@
9653
+ * @public exported from `@promptbook/node`
9654
+ */
9655
+ async function $provideLlmToolsConfigurationFromEnv() {
9656
+ if (!$isRunningInNode()) {
9657
+ throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9658
+ }
9659
+ const envFilepath = await $provideEnvFilename();
9660
+ if (envFilepath !== null) {
9661
+ dotenv__namespace.config({ path: envFilepath });
9662
+ }
9555
9663
  const llmToolsConfiguration = $llmToolsMetadataRegister
9556
9664
  .list()
9557
9665
  .map((metadata) => metadata.createConfigurationFromEnv(process.env))
@@ -9559,15 +9667,8 @@
9559
9667
  return llmToolsConfiguration;
9560
9668
  }
9561
9669
  /**
9562
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
9563
- * TODO: Add Azure OpenAI
9564
- * TODO: [🧠][🍛]
9565
- * TODO: [🧠] Is there some meaningfull way how to test this util
9566
9670
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9567
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
9568
- * TODO: This should be maybe not under `_common` but under `utils`
9569
- * TODO: [🧠][⚛] Maybe pass env as argument
9570
- * TODO: [®] DRY Register logic */
9671
+ */
9571
9672
 
9572
9673
  /**
9573
9674
  * @@@
@@ -9626,6 +9727,7 @@
9626
9727
  * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
9627
9728
  *
9628
9729
  * @@@ .env
9730
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
9629
9731
  *
9630
9732
  * It looks for environment variables:
9631
9733
  * - `process.env.OPENAI_API_KEY`