@promptbook/node 0.89.0-8 → 0.89.0

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 -11
  2. package/esm/index.es.js +200 -84
  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 +12 -4
  6. package/esm/typings/src/_packages/remote-client.index.d.ts +6 -6
  7. package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
  8. package/esm/typings/src/_packages/types.index.d.ts +24 -14
  9. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  10. package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
  11. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
  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 +10 -19
  15. package/esm/typings/src/errors/0-index.d.ts +8 -2
  16. package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
  17. package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
  18. package/esm/typings/src/errors/WrappedError.d.ts +10 -0
  19. package/esm/typings/src/errors/assertsError.d.ts +11 -0
  20. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  21. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
  22. package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
  23. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
  24. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
  25. package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
  26. package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
  27. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
  28. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
  29. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +15 -4
  30. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
  31. package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
  32. package/esm/typings/src/remote-server/openapi.d.ts +187 -0
  33. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +9 -3
  34. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  35. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  36. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  37. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  38. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  39. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  40. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +2 -2
  41. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +57 -38
  42. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  43. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  44. package/esm/typings/src/types/typeAliases.d.ts +26 -0
  45. package/package.json +9 -5
  46. package/umd/index.umd.js +200 -84
  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/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.89.0-8';
49
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0';
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
@@ -92,6 +92,7 @@
92
92
  * @public exported from `@promptbook/core`
93
93
  */
94
94
  const ADMIN_GITHUB_NAME = 'hejny';
95
+ // <- TODO: [🐊] Pick the best claim
95
96
  /**
96
97
  * When the title is not provided, the default title is used
97
98
  *
@@ -136,6 +137,7 @@
136
137
  infinity: '(infinity; ∞)',
137
138
  negativeInfinity: '(negative infinity; -∞)',
138
139
  unserializable: '(unserializable value)',
140
+ circular: '(circular JSON)',
139
141
  };
140
142
  /**
141
143
  * Small number limit
@@ -175,7 +177,7 @@
175
177
  */
176
178
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹‍♂️]
177
179
  // <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
178
- // TODO: !!!!!! Just .promptbook dir, hardocode others
180
+ // TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
179
181
  /**
180
182
  * Where to store the temporary downloads
181
183
  *
@@ -355,6 +357,54 @@
355
357
  * TODO: [🧠] Is there a way how to meaningfully test this utility
356
358
  */
357
359
 
360
+ /**
361
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
362
+ *
363
+ * @public exported from `@promptbook/core`
364
+ */
365
+ class WrappedError extends Error {
366
+ constructor(whatWasThrown) {
367
+ const tag = `[🤮]`;
368
+ console.error(tag, whatWasThrown);
369
+ super(spaceTrim.spaceTrim(`
370
+ Non-Error object was thrown
371
+
372
+ Note: Look for ${tag} in the console for more details
373
+ Please report issue on ${ADMIN_EMAIL}
374
+ `));
375
+ this.name = 'WrappedError';
376
+ Object.setPrototypeOf(this, WrappedError.prototype);
377
+ }
378
+ }
379
+
380
+ /**
381
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
382
+ *
383
+ * @param whatWasThrown Any object that was thrown
384
+ * @returns Nothing if the error is an instance of `Error`
385
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
386
+ *
387
+ * @private within the repository
388
+ */
389
+ function assertsError(whatWasThrown) {
390
+ // Case 1: Handle error which was rethrown as `WrappedError`
391
+ if (whatWasThrown instanceof WrappedError) {
392
+ const wrappedError = whatWasThrown;
393
+ throw wrappedError;
394
+ }
395
+ // Case 2: Handle unexpected errors
396
+ if (whatWasThrown instanceof UnexpectedError) {
397
+ const unexpectedError = whatWasThrown;
398
+ throw unexpectedError;
399
+ }
400
+ // Case 3: Handle standard errors - keep them up to consumer
401
+ if (whatWasThrown instanceof Error) {
402
+ return;
403
+ }
404
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
405
+ throw new WrappedError(whatWasThrown);
406
+ }
407
+
358
408
  /**
359
409
  * Checks if the value is [🚉] serializable as JSON
360
410
  * If not, throws an UnexpectedError with a rich error message and tracking
@@ -446,9 +496,7 @@
446
496
  JSON.stringify(value); // <- TODO: [0]
447
497
  }
448
498
  catch (error) {
449
- if (!(error instanceof Error)) {
450
- throw error;
451
- }
499
+ assertsError(error);
452
500
  throw new UnexpectedError(spaceTrim__default["default"]((block) => `
453
501
  \`${name}\` is not serializable
454
502
 
@@ -1135,6 +1183,9 @@
1135
1183
  /**
1136
1184
  * Function isValidJsonString will tell you if the string is valid JSON or not
1137
1185
  *
1186
+ * @param value The string to check
1187
+ * @returns True if the string is a valid JSON string, false otherwise
1188
+ *
1138
1189
  * @public exported from `@promptbook/utils`
1139
1190
  */
1140
1191
  function isValidJsonString(value /* <- [👨‍⚖️] */) {
@@ -1143,9 +1194,7 @@
1143
1194
  return true;
1144
1195
  }
1145
1196
  catch (error) {
1146
- if (!(error instanceof Error)) {
1147
- throw error;
1148
- }
1197
+ assertsError(error);
1149
1198
  if (error.message.includes('Unexpected token')) {
1150
1199
  return false;
1151
1200
  }
@@ -1677,7 +1726,7 @@
1677
1726
  }
1678
1727
  }
1679
1728
  /**
1680
- * TODO: !!!!!! Add id to all errors
1729
+ * TODO: [🧠][🌂] Add id to all errors
1681
1730
  */
1682
1731
 
1683
1732
  /**
@@ -1814,6 +1863,19 @@
1814
1863
  }
1815
1864
  }
1816
1865
 
1866
+ /**
1867
+ * Error thrown when a fetch request fails
1868
+ *
1869
+ * @public exported from `@promptbook/core`
1870
+ */
1871
+ class PromptbookFetchError extends Error {
1872
+ constructor(message) {
1873
+ super(message);
1874
+ this.name = 'PromptbookFetchError';
1875
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
1876
+ }
1877
+ }
1878
+
1817
1879
  /**
1818
1880
  * Index of all custom errors
1819
1881
  *
@@ -1834,7 +1896,10 @@
1834
1896
  PipelineExecutionError,
1835
1897
  PipelineLogicError,
1836
1898
  PipelineUrlError,
1899
+ AuthenticationError,
1900
+ PromptbookFetchError,
1837
1901
  UnexpectedError,
1902
+ WrappedError,
1838
1903
  // TODO: [🪑]> VersionMismatchError,
1839
1904
  };
1840
1905
  /**
@@ -1851,7 +1916,6 @@
1851
1916
  TypeError,
1852
1917
  URIError,
1853
1918
  AggregateError,
1854
- AuthenticationError,
1855
1919
  /*
1856
1920
  Note: Not widely supported
1857
1921
  > InternalError,
@@ -1974,8 +2038,8 @@
1974
2038
  updatedAt = new Date();
1975
2039
  errors.push(...executionResult.errors);
1976
2040
  warnings.push(...executionResult.warnings);
1977
- // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
1978
- // TODO: [🧠] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2041
+ // <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
2042
+ // TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
1979
2043
  // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
1980
2044
  // And delete `ExecutionTask.currentValue.preparedPipeline`
1981
2045
  assertsTaskSuccessful(executionResult);
@@ -1985,6 +2049,7 @@
1985
2049
  partialResultSubject.next(executionResult);
1986
2050
  }
1987
2051
  catch (error) {
2052
+ assertsError(error);
1988
2053
  status = 'ERROR';
1989
2054
  errors.push(error);
1990
2055
  partialResultSubject.error(error);
@@ -2130,13 +2195,19 @@
2130
2195
  return value.toISOString();
2131
2196
  }
2132
2197
  else {
2133
- return JSON.stringify(value);
2198
+ try {
2199
+ return JSON.stringify(value);
2200
+ }
2201
+ catch (error) {
2202
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
2203
+ return VALUE_STRINGS.circular;
2204
+ }
2205
+ throw error;
2206
+ }
2134
2207
  }
2135
2208
  }
2136
2209
  catch (error) {
2137
- if (!(error instanceof Error)) {
2138
- throw error;
2139
- }
2210
+ assertsError(error);
2140
2211
  console.error(error);
2141
2212
  return VALUE_STRINGS.unserializable;
2142
2213
  }
@@ -2308,9 +2379,7 @@
2308
2379
  }
2309
2380
  }
2310
2381
  catch (error) {
2311
- if (!(error instanceof Error)) {
2312
- throw error;
2313
- }
2382
+ assertsError(error);
2314
2383
  throw new ParseError(spaceTrim.spaceTrim((block) => `
2315
2384
  Can not extract variables from the script
2316
2385
  ${block(error.stack || error.message)}
@@ -2429,6 +2498,28 @@
2429
2498
  // encoding: 'utf-8',
2430
2499
  });
2431
2500
 
2501
+ /**
2502
+ * Function to check if a string is valid CSV
2503
+ *
2504
+ * @param value The string to check
2505
+ * @returns True if the string is a valid CSV string, false otherwise
2506
+ *
2507
+ * @public exported from `@promptbook/utils`
2508
+ */
2509
+ function isValidCsvString(value) {
2510
+ try {
2511
+ // A simple check for CSV format: at least one comma and no invalid characters
2512
+ if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
2513
+ return true;
2514
+ }
2515
+ return false;
2516
+ }
2517
+ catch (error) {
2518
+ assertsError(error);
2519
+ return false;
2520
+ }
2521
+ }
2522
+
2432
2523
  /**
2433
2524
  * Definition for CSV spreadsheet
2434
2525
  *
@@ -2439,7 +2530,7 @@
2439
2530
  formatName: 'CSV',
2440
2531
  aliases: ['SPREADSHEET', 'TABLE'],
2441
2532
  isValid(value, settings, schema) {
2442
- return true;
2533
+ return isValidCsvString(value);
2443
2534
  },
2444
2535
  canBeValid(partialValue, settings, schema) {
2445
2536
  return true;
@@ -2593,6 +2684,30 @@
2593
2684
  * TODO: [🏢] Allow to expect something inside each item of list and other formats
2594
2685
  */
2595
2686
 
2687
+ /**
2688
+ * Function to check if a string is valid XML
2689
+ *
2690
+ * @param value
2691
+ * @returns True if the string is a valid XML string, false otherwise
2692
+ *
2693
+ * @public exported from `@promptbook/utils`
2694
+ */
2695
+ function isValidXmlString(value) {
2696
+ try {
2697
+ const parser = new DOMParser();
2698
+ const parsedDocument = parser.parseFromString(value, 'application/xml');
2699
+ const parserError = parsedDocument.getElementsByTagName('parsererror');
2700
+ if (parserError.length > 0) {
2701
+ return false;
2702
+ }
2703
+ return true;
2704
+ }
2705
+ catch (error) {
2706
+ assertsError(error);
2707
+ return false;
2708
+ }
2709
+ }
2710
+
2596
2711
  /**
2597
2712
  * Definition for XML format
2598
2713
  *
@@ -2602,7 +2717,7 @@
2602
2717
  formatName: 'XML',
2603
2718
  mimeType: 'application/xml',
2604
2719
  isValid(value, settings, schema) {
2605
- return true;
2720
+ return isValidXmlString(value);
2606
2721
  },
2607
2722
  canBeValid(partialValue, settings, schema) {
2608
2723
  return true;
@@ -2799,14 +2914,15 @@
2799
2914
  }
2800
2915
  }
2801
2916
  catch (error) {
2802
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
2917
+ assertsError(error);
2918
+ if (error instanceof UnexpectedError) {
2803
2919
  throw error;
2804
2920
  }
2805
2921
  errors.push({ llmExecutionTools, error });
2806
2922
  }
2807
2923
  }
2808
2924
  if (errors.length === 1) {
2809
- throw errors[0];
2925
+ throw errors[0].error;
2810
2926
  }
2811
2927
  else if (errors.length > 1) {
2812
2928
  throw new PipelineExecutionError(
@@ -3663,9 +3779,7 @@
3663
3779
  break scripts;
3664
3780
  }
3665
3781
  catch (error) {
3666
- if (!(error instanceof Error)) {
3667
- throw error;
3668
- }
3782
+ assertsError(error);
3669
3783
  if (error instanceof UnexpectedError) {
3670
3784
  throw error;
3671
3785
  }
@@ -3735,9 +3849,7 @@
3735
3849
  break scripts;
3736
3850
  }
3737
3851
  catch (error) {
3738
- if (!(error instanceof Error)) {
3739
- throw error;
3740
- }
3852
+ assertsError(error);
3741
3853
  if (error instanceof UnexpectedError) {
3742
3854
  throw error;
3743
3855
  }
@@ -4358,9 +4470,7 @@
4358
4470
  await Promise.all(resolving);
4359
4471
  }
4360
4472
  catch (error /* <- Note: [3] */) {
4361
- if (!(error instanceof Error)) {
4362
- throw error;
4363
- }
4473
+ assertsError(error);
4364
4474
  // Note: No need to rethrow UnexpectedError
4365
4475
  // if (error instanceof UnexpectedError) {
4366
4476
  // Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹‍♂️]
@@ -5063,17 +5173,22 @@
5063
5173
  /**
5064
5174
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
5065
5175
  *
5066
- * @private as default `fetch` function used in Promptbook scrapers
5176
+ * @public exported from `@promptbook/core`
5067
5177
  */
5068
- const scraperFetch = async (url, init) => {
5178
+ const promptbookFetch = async (urlOrRequest, init) => {
5069
5179
  try {
5070
- return await fetch(url, init);
5180
+ return await fetch(urlOrRequest, init);
5071
5181
  }
5072
5182
  catch (error) {
5073
- if (!(error instanceof Error)) {
5074
- throw error;
5183
+ assertsError(error);
5184
+ let url;
5185
+ if (typeof urlOrRequest === 'string') {
5186
+ url = urlOrRequest;
5075
5187
  }
5076
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
5188
+ else if (urlOrRequest instanceof Request) {
5189
+ url = urlOrRequest.url;
5190
+ }
5191
+ throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
5077
5192
  Can not fetch "${url}"
5078
5193
 
5079
5194
  Fetch error:
@@ -5094,7 +5209,7 @@
5094
5209
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
5095
5210
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
5096
5211
  var _a;
5097
- const { fetch = scraperFetch } = tools;
5212
+ const { fetch = promptbookFetch } = tools;
5098
5213
  const { knowledgeSourceContent } = knowledgeSource;
5099
5214
  let { name } = knowledgeSource;
5100
5215
  const { rootDirname = null,
@@ -5296,9 +5411,7 @@
5296
5411
  knowledgePreparedUnflatten[index] = pieces;
5297
5412
  }
5298
5413
  catch (error) {
5299
- if (!(error instanceof Error)) {
5300
- throw error;
5301
- }
5414
+ assertsError(error);
5302
5415
  console.warn(error);
5303
5416
  // <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
5304
5417
  }
@@ -6096,6 +6209,8 @@
6096
6209
  */
6097
6210
 
6098
6211
  /**
6212
+ import { WrappedError } from '../../errors/WrappedError';
6213
+ import { assertsError } from '../../errors/assertsError';
6099
6214
  * Parses the expect command
6100
6215
  *
6101
6216
  * @see `documentationUrl` for more details
@@ -6187,9 +6302,7 @@
6187
6302
  };
6188
6303
  }
6189
6304
  catch (error) {
6190
- if (!(error instanceof Error)) {
6191
- throw error;
6192
- }
6305
+ assertsError(error);
6193
6306
  throw new ParseError(spaceTrim__default["default"]((block) => `
6194
6307
  Invalid FORMAT command
6195
6308
  ${block(error.message)}:
@@ -9170,9 +9283,7 @@
9170
9283
  return result.trim();
9171
9284
  }
9172
9285
  catch (error) {
9173
- if (!(error instanceof Error)) {
9174
- throw error;
9175
- }
9286
+ assertsError(error);
9176
9287
  return null;
9177
9288
  }
9178
9289
  }
@@ -9250,9 +9361,7 @@
9250
9361
  return result.trim() + toExec;
9251
9362
  }
9252
9363
  catch (error) {
9253
- if (!(error instanceof Error)) {
9254
- throw error;
9255
- }
9364
+ assertsError(error);
9256
9365
  return null;
9257
9366
  }
9258
9367
  }
@@ -9283,9 +9392,7 @@
9283
9392
  throw new Error(`Can not locate app ${appName} on Windows.`);
9284
9393
  }
9285
9394
  catch (error) {
9286
- if (!(error instanceof Error)) {
9287
- throw error;
9288
- }
9395
+ assertsError(error);
9289
9396
  return null;
9290
9397
  }
9291
9398
  }
@@ -9574,21 +9681,15 @@
9574
9681
  */
9575
9682
 
9576
9683
  /**
9577
- * @@@
9578
- *
9579
- * @@@ .env
9684
+ * Provides the path to the `.env` file
9580
9685
  *
9581
- * It looks for environment variables:
9582
- * - `process.env.OPENAI_API_KEY`
9583
- * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9584
- * - ...
9686
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
9585
9687
  *
9586
- * @returns @@@
9587
- * @public exported from `@promptbook/node`
9688
+ * @private within the repository - for CLI utils
9588
9689
  */
9589
- async function $provideLlmToolsConfigurationFromEnv() {
9690
+ async function $provideEnvFilename() {
9590
9691
  if (!$isRunningInNode()) {
9591
- throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9692
+ throw new EnvironmentMismatchError('Function `$provideEnvFilename` works only in Node.js environment');
9592
9693
  }
9593
9694
  const envFilePatterns = [
9594
9695
  '.env',
@@ -9608,8 +9709,7 @@
9608
9709
  const envFilename = path.join(rootDirname, pattern);
9609
9710
  if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
9610
9711
  $setUsedEnvFilename(envFilename);
9611
- dotenv__namespace.config({ path: envFilename });
9612
- break up_to_root;
9712
+ return envFilename;
9613
9713
  }
9614
9714
  }
9615
9715
  if (isRootPath(rootDirname)) {
@@ -9618,6 +9718,34 @@
9618
9718
  // Note: If the directory does not exist, try the parent directory
9619
9719
  rootDirname = path.join(rootDirname, '..');
9620
9720
  }
9721
+ return null;
9722
+ }
9723
+ /**
9724
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9725
+ */
9726
+
9727
+ /**
9728
+ * @@@
9729
+ *
9730
+ * @@@ .env
9731
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
9732
+ *
9733
+ * It looks for environment variables:
9734
+ * - `process.env.OPENAI_API_KEY`
9735
+ * - `process.env.ANTHROPIC_CLAUDE_API_KEY`
9736
+ * - ...
9737
+ *
9738
+ * @returns @@@
9739
+ * @public exported from `@promptbook/node`
9740
+ */
9741
+ async function $provideLlmToolsConfigurationFromEnv() {
9742
+ if (!$isRunningInNode()) {
9743
+ throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
9744
+ }
9745
+ const envFilepath = await $provideEnvFilename();
9746
+ if (envFilepath !== null) {
9747
+ dotenv__namespace.config({ path: envFilepath });
9748
+ }
9621
9749
  const llmToolsConfiguration = $llmToolsMetadataRegister
9622
9750
  .list()
9623
9751
  .map((metadata) => metadata.createConfigurationFromEnv(process.env))
@@ -9625,15 +9753,8 @@
9625
9753
  return llmToolsConfiguration;
9626
9754
  }
9627
9755
  /**
9628
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
9629
- * TODO: Add Azure OpenAI
9630
- * TODO: [🧠][🍛]
9631
- * TODO: [🧠] Is there some meaningfull way how to test this util
9632
9756
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
9633
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
9634
- * TODO: This should be maybe not under `_common` but under `utils`
9635
- * TODO: [🧠][⚛] Maybe pass env as argument
9636
- * TODO: [®] DRY Register logic */
9757
+ */
9637
9758
 
9638
9759
  /**
9639
9760
  * @@@
@@ -9692,6 +9813,7 @@
9692
9813
  * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
9693
9814
  *
9694
9815
  * @@@ .env
9816
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
9695
9817
  *
9696
9818
  * It looks for environment variables:
9697
9819
  * - `process.env.OPENAI_API_KEY`
@@ -10225,9 +10347,7 @@
10225
10347
  }
10226
10348
  }
10227
10349
  catch (error) {
10228
- if (!(error instanceof Error)) {
10229
- throw error;
10230
- }
10350
+ assertsError(error);
10231
10351
  if (error instanceof ReferenceError) {
10232
10352
  const undefinedName = error.message.split(' ')[0];
10233
10353
  /*
@@ -10502,9 +10622,7 @@
10502
10622
  // ---
10503
10623
  }
10504
10624
  catch (error) {
10505
- if (!(error instanceof Error)) {
10506
- throw error;
10507
- }
10625
+ assertsError(error);
10508
10626
  // TODO: [7] DRY
10509
10627
  const wrappedErrorMessage = spaceTrim__default["default"]((block) => `
10510
10628
  ${error.name} in pipeline ${fileName.split('\\').join('/')}⁠:
@@ -10595,9 +10713,7 @@
10595
10713
  }
10596
10714
  }
10597
10715
  catch (error) {
10598
- if (!(error instanceof Error)) {
10599
- throw error;
10600
- }
10716
+ assertsError(error);
10601
10717
  // TODO: [7] DRY
10602
10718
  const wrappedErrorMessage = spaceTrim__default["default"]((block) => `
10603
10719
  ${error.name} in pipeline ${fileName.split('\\').join('/')}⁠: