@promptbook/node 0.89.0-3 → 0.89.0-30
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.
- package/README.md +9 -7
- package/esm/index.es.js +176 -81
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +40 -0
- package/esm/typings/src/_packages/core.index.d.ts +20 -8
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +24 -12
- package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +28 -0
- package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
- package/esm/typings/src/config.d.ts +24 -26
- package/esm/typings/src/errors/0-index.d.ts +9 -0
- package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
- package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
- package/esm/typings/src/errors/WrappedError.d.ts +10 -0
- package/esm/typings/src/errors/assertsError.d.ts +11 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +45 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
- package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
- package/esm/typings/src/remote-server/openapi.d.ts +187 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
- package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +3 -4
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +84 -9
- package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
- package/esm/typings/src/types/typeAliases.d.ts +19 -0
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +9 -5
- package/umd/index.umd.js +176 -81
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
- package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
- 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-
|
|
49
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-30';
|
|
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,6 +177,7 @@
|
|
|
175
177
|
*/
|
|
176
178
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
177
179
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
180
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
178
181
|
/**
|
|
179
182
|
* Where to store the temporary downloads
|
|
180
183
|
*
|
|
@@ -191,6 +194,15 @@
|
|
|
191
194
|
* @public exported from `@promptbook/core`
|
|
192
195
|
*/
|
|
193
196
|
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
197
|
+
/*
|
|
198
|
+
TODO: [🌃]
|
|
199
|
+
/**
|
|
200
|
+
* Id of application for the wizzard when using remote server
|
|
201
|
+
*
|
|
202
|
+
* @public exported from `@promptbook/core`
|
|
203
|
+
* /
|
|
204
|
+
ex-port const WIZZARD_APP_ID: string_app_id = 'wizzard';
|
|
205
|
+
*/
|
|
194
206
|
/**
|
|
195
207
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
196
208
|
*
|
|
@@ -232,7 +244,7 @@
|
|
|
232
244
|
true);
|
|
233
245
|
/**
|
|
234
246
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
235
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
247
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
236
248
|
*/
|
|
237
249
|
|
|
238
250
|
/**
|
|
@@ -345,6 +357,54 @@
|
|
|
345
357
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
346
358
|
*/
|
|
347
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
|
+
|
|
348
408
|
/**
|
|
349
409
|
* Checks if the value is [🚉] serializable as JSON
|
|
350
410
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -436,9 +496,7 @@
|
|
|
436
496
|
JSON.stringify(value); // <- TODO: [0]
|
|
437
497
|
}
|
|
438
498
|
catch (error) {
|
|
439
|
-
|
|
440
|
-
throw error;
|
|
441
|
-
}
|
|
499
|
+
assertsError(error);
|
|
442
500
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
443
501
|
\`${name}\` is not serializable
|
|
444
502
|
|
|
@@ -1133,9 +1191,7 @@
|
|
|
1133
1191
|
return true;
|
|
1134
1192
|
}
|
|
1135
1193
|
catch (error) {
|
|
1136
|
-
|
|
1137
|
-
throw error;
|
|
1138
|
-
}
|
|
1194
|
+
assertsError(error);
|
|
1139
1195
|
if (error.message.includes('Unexpected token')) {
|
|
1140
1196
|
return false;
|
|
1141
1197
|
}
|
|
@@ -1667,7 +1723,7 @@
|
|
|
1667
1723
|
}
|
|
1668
1724
|
}
|
|
1669
1725
|
/**
|
|
1670
|
-
* TODO:
|
|
1726
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
1671
1727
|
*/
|
|
1672
1728
|
|
|
1673
1729
|
/**
|
|
@@ -1700,6 +1756,19 @@
|
|
|
1700
1756
|
}
|
|
1701
1757
|
}
|
|
1702
1758
|
|
|
1759
|
+
/**
|
|
1760
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
1761
|
+
*
|
|
1762
|
+
* @public exported from `@promptbook/core`
|
|
1763
|
+
*/
|
|
1764
|
+
class AuthenticationError extends Error {
|
|
1765
|
+
constructor(message) {
|
|
1766
|
+
super(message);
|
|
1767
|
+
this.name = 'AuthenticationError';
|
|
1768
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1703
1772
|
/**
|
|
1704
1773
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1705
1774
|
*
|
|
@@ -1791,6 +1860,19 @@
|
|
|
1791
1860
|
}
|
|
1792
1861
|
}
|
|
1793
1862
|
|
|
1863
|
+
/**
|
|
1864
|
+
* Error thrown when a fetch request fails
|
|
1865
|
+
*
|
|
1866
|
+
* @public exported from `@promptbook/core`
|
|
1867
|
+
*/
|
|
1868
|
+
class PromptbookFetchError extends Error {
|
|
1869
|
+
constructor(message) {
|
|
1870
|
+
super(message);
|
|
1871
|
+
this.name = 'PromptbookFetchError';
|
|
1872
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1794
1876
|
/**
|
|
1795
1877
|
* Index of all custom errors
|
|
1796
1878
|
*
|
|
@@ -1811,7 +1893,10 @@
|
|
|
1811
1893
|
PipelineExecutionError,
|
|
1812
1894
|
PipelineLogicError,
|
|
1813
1895
|
PipelineUrlError,
|
|
1896
|
+
AuthenticationError,
|
|
1897
|
+
PromptbookFetchError,
|
|
1814
1898
|
UnexpectedError,
|
|
1899
|
+
WrappedError,
|
|
1815
1900
|
// TODO: [🪑]> VersionMismatchError,
|
|
1816
1901
|
};
|
|
1817
1902
|
/**
|
|
@@ -1950,8 +2035,8 @@
|
|
|
1950
2035
|
updatedAt = new Date();
|
|
1951
2036
|
errors.push(...executionResult.errors);
|
|
1952
2037
|
warnings.push(...executionResult.warnings);
|
|
1953
|
-
// <- TODO:
|
|
1954
|
-
// TODO: [🧠]
|
|
2038
|
+
// <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
|
|
2039
|
+
// TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
1955
2040
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
1956
2041
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
1957
2042
|
assertsTaskSuccessful(executionResult);
|
|
@@ -1961,6 +2046,7 @@
|
|
|
1961
2046
|
partialResultSubject.next(executionResult);
|
|
1962
2047
|
}
|
|
1963
2048
|
catch (error) {
|
|
2049
|
+
assertsError(error);
|
|
1964
2050
|
status = 'ERROR';
|
|
1965
2051
|
errors.push(error);
|
|
1966
2052
|
partialResultSubject.error(error);
|
|
@@ -2027,6 +2113,10 @@
|
|
|
2027
2113
|
|
|
2028
2114
|
Cannot serialize error with name "${name}"
|
|
2029
2115
|
|
|
2116
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2117
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2118
|
+
|
|
2119
|
+
|
|
2030
2120
|
${block(stack || message)}
|
|
2031
2121
|
|
|
2032
2122
|
`));
|
|
@@ -2102,13 +2192,19 @@
|
|
|
2102
2192
|
return value.toISOString();
|
|
2103
2193
|
}
|
|
2104
2194
|
else {
|
|
2105
|
-
|
|
2195
|
+
try {
|
|
2196
|
+
return JSON.stringify(value);
|
|
2197
|
+
}
|
|
2198
|
+
catch (error) {
|
|
2199
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
2200
|
+
return VALUE_STRINGS.circular;
|
|
2201
|
+
}
|
|
2202
|
+
throw error;
|
|
2203
|
+
}
|
|
2106
2204
|
}
|
|
2107
2205
|
}
|
|
2108
2206
|
catch (error) {
|
|
2109
|
-
|
|
2110
|
-
throw error;
|
|
2111
|
-
}
|
|
2207
|
+
assertsError(error);
|
|
2112
2208
|
console.error(error);
|
|
2113
2209
|
return VALUE_STRINGS.unserializable;
|
|
2114
2210
|
}
|
|
@@ -2280,9 +2376,7 @@
|
|
|
2280
2376
|
}
|
|
2281
2377
|
}
|
|
2282
2378
|
catch (error) {
|
|
2283
|
-
|
|
2284
|
-
throw error;
|
|
2285
|
-
}
|
|
2379
|
+
assertsError(error);
|
|
2286
2380
|
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
2287
2381
|
Can not extract variables from the script
|
|
2288
2382
|
${block(error.stack || error.message)}
|
|
@@ -2771,14 +2865,15 @@
|
|
|
2771
2865
|
}
|
|
2772
2866
|
}
|
|
2773
2867
|
catch (error) {
|
|
2774
|
-
|
|
2868
|
+
assertsError(error);
|
|
2869
|
+
if (error instanceof UnexpectedError) {
|
|
2775
2870
|
throw error;
|
|
2776
2871
|
}
|
|
2777
2872
|
errors.push({ llmExecutionTools, error });
|
|
2778
2873
|
}
|
|
2779
2874
|
}
|
|
2780
2875
|
if (errors.length === 1) {
|
|
2781
|
-
throw errors[0];
|
|
2876
|
+
throw errors[0].error;
|
|
2782
2877
|
}
|
|
2783
2878
|
else if (errors.length > 1) {
|
|
2784
2879
|
throw new PipelineExecutionError(
|
|
@@ -3635,9 +3730,7 @@
|
|
|
3635
3730
|
break scripts;
|
|
3636
3731
|
}
|
|
3637
3732
|
catch (error) {
|
|
3638
|
-
|
|
3639
|
-
throw error;
|
|
3640
|
-
}
|
|
3733
|
+
assertsError(error);
|
|
3641
3734
|
if (error instanceof UnexpectedError) {
|
|
3642
3735
|
throw error;
|
|
3643
3736
|
}
|
|
@@ -3707,9 +3800,7 @@
|
|
|
3707
3800
|
break scripts;
|
|
3708
3801
|
}
|
|
3709
3802
|
catch (error) {
|
|
3710
|
-
|
|
3711
|
-
throw error;
|
|
3712
|
-
}
|
|
3803
|
+
assertsError(error);
|
|
3713
3804
|
if (error instanceof UnexpectedError) {
|
|
3714
3805
|
throw error;
|
|
3715
3806
|
}
|
|
@@ -4330,9 +4421,7 @@
|
|
|
4330
4421
|
await Promise.all(resolving);
|
|
4331
4422
|
}
|
|
4332
4423
|
catch (error /* <- Note: [3] */) {
|
|
4333
|
-
|
|
4334
|
-
throw error;
|
|
4335
|
-
}
|
|
4424
|
+
assertsError(error);
|
|
4336
4425
|
// Note: No need to rethrow UnexpectedError
|
|
4337
4426
|
// if (error instanceof UnexpectedError) {
|
|
4338
4427
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|
|
@@ -5035,17 +5124,22 @@
|
|
|
5035
5124
|
/**
|
|
5036
5125
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5037
5126
|
*
|
|
5038
|
-
* @
|
|
5127
|
+
* @public exported from `@promptbook/core`
|
|
5039
5128
|
*/
|
|
5040
|
-
const
|
|
5129
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
5041
5130
|
try {
|
|
5042
|
-
return await fetch(
|
|
5131
|
+
return await fetch(urlOrRequest, init);
|
|
5043
5132
|
}
|
|
5044
5133
|
catch (error) {
|
|
5045
|
-
|
|
5046
|
-
|
|
5134
|
+
assertsError(error);
|
|
5135
|
+
let url;
|
|
5136
|
+
if (typeof urlOrRequest === 'string') {
|
|
5137
|
+
url = urlOrRequest;
|
|
5138
|
+
}
|
|
5139
|
+
else if (urlOrRequest instanceof Request) {
|
|
5140
|
+
url = urlOrRequest.url;
|
|
5047
5141
|
}
|
|
5048
|
-
throw new
|
|
5142
|
+
throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
|
|
5049
5143
|
Can not fetch "${url}"
|
|
5050
5144
|
|
|
5051
5145
|
Fetch error:
|
|
@@ -5066,7 +5160,7 @@
|
|
|
5066
5160
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5067
5161
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
5068
5162
|
var _a;
|
|
5069
|
-
const { fetch =
|
|
5163
|
+
const { fetch = promptbookFetch } = tools;
|
|
5070
5164
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
5071
5165
|
let { name } = knowledgeSource;
|
|
5072
5166
|
const { rootDirname = null,
|
|
@@ -5268,9 +5362,7 @@
|
|
|
5268
5362
|
knowledgePreparedUnflatten[index] = pieces;
|
|
5269
5363
|
}
|
|
5270
5364
|
catch (error) {
|
|
5271
|
-
|
|
5272
|
-
throw error;
|
|
5273
|
-
}
|
|
5365
|
+
assertsError(error);
|
|
5274
5366
|
console.warn(error);
|
|
5275
5367
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5276
5368
|
}
|
|
@@ -6068,6 +6160,8 @@
|
|
|
6068
6160
|
*/
|
|
6069
6161
|
|
|
6070
6162
|
/**
|
|
6163
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
6164
|
+
import { assertsError } from '../../errors/assertsError';
|
|
6071
6165
|
* Parses the expect command
|
|
6072
6166
|
*
|
|
6073
6167
|
* @see `documentationUrl` for more details
|
|
@@ -6159,9 +6253,7 @@
|
|
|
6159
6253
|
};
|
|
6160
6254
|
}
|
|
6161
6255
|
catch (error) {
|
|
6162
|
-
|
|
6163
|
-
throw error;
|
|
6164
|
-
}
|
|
6256
|
+
assertsError(error);
|
|
6165
6257
|
throw new ParseError(spaceTrim__default["default"]((block) => `
|
|
6166
6258
|
Invalid FORMAT command
|
|
6167
6259
|
${block(error.message)}:
|
|
@@ -9142,9 +9234,7 @@
|
|
|
9142
9234
|
return result.trim();
|
|
9143
9235
|
}
|
|
9144
9236
|
catch (error) {
|
|
9145
|
-
|
|
9146
|
-
throw error;
|
|
9147
|
-
}
|
|
9237
|
+
assertsError(error);
|
|
9148
9238
|
return null;
|
|
9149
9239
|
}
|
|
9150
9240
|
}
|
|
@@ -9222,9 +9312,7 @@
|
|
|
9222
9312
|
return result.trim() + toExec;
|
|
9223
9313
|
}
|
|
9224
9314
|
catch (error) {
|
|
9225
|
-
|
|
9226
|
-
throw error;
|
|
9227
|
-
}
|
|
9315
|
+
assertsError(error);
|
|
9228
9316
|
return null;
|
|
9229
9317
|
}
|
|
9230
9318
|
}
|
|
@@ -9255,9 +9343,7 @@
|
|
|
9255
9343
|
throw new Error(`Can not locate app ${appName} on Windows.`);
|
|
9256
9344
|
}
|
|
9257
9345
|
catch (error) {
|
|
9258
|
-
|
|
9259
|
-
throw error;
|
|
9260
|
-
}
|
|
9346
|
+
assertsError(error);
|
|
9261
9347
|
return null;
|
|
9262
9348
|
}
|
|
9263
9349
|
}
|
|
@@ -9546,21 +9632,15 @@
|
|
|
9546
9632
|
*/
|
|
9547
9633
|
|
|
9548
9634
|
/**
|
|
9549
|
-
*
|
|
9550
|
-
*
|
|
9551
|
-
* @@@ .env
|
|
9635
|
+
* Provides the path to the `.env` file
|
|
9552
9636
|
*
|
|
9553
|
-
*
|
|
9554
|
-
* - `process.env.OPENAI_API_KEY`
|
|
9555
|
-
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9556
|
-
* - ...
|
|
9637
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9557
9638
|
*
|
|
9558
|
-
* @
|
|
9559
|
-
* @public exported from `@promptbook/node`
|
|
9639
|
+
* @private within the repository - for CLI utils
|
|
9560
9640
|
*/
|
|
9561
|
-
async function $
|
|
9641
|
+
async function $provideEnvFilename() {
|
|
9562
9642
|
if (!$isRunningInNode()) {
|
|
9563
|
-
throw new EnvironmentMismatchError('Function `$
|
|
9643
|
+
throw new EnvironmentMismatchError('Function `$provideEnvFilename` works only in Node.js environment');
|
|
9564
9644
|
}
|
|
9565
9645
|
const envFilePatterns = [
|
|
9566
9646
|
'.env',
|
|
@@ -9580,8 +9660,7 @@
|
|
|
9580
9660
|
const envFilename = path.join(rootDirname, pattern);
|
|
9581
9661
|
if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
|
|
9582
9662
|
$setUsedEnvFilename(envFilename);
|
|
9583
|
-
|
|
9584
|
-
break up_to_root;
|
|
9663
|
+
return envFilename;
|
|
9585
9664
|
}
|
|
9586
9665
|
}
|
|
9587
9666
|
if (isRootPath(rootDirname)) {
|
|
@@ -9590,6 +9669,34 @@
|
|
|
9590
9669
|
// Note: If the directory does not exist, try the parent directory
|
|
9591
9670
|
rootDirname = path.join(rootDirname, '..');
|
|
9592
9671
|
}
|
|
9672
|
+
return null;
|
|
9673
|
+
}
|
|
9674
|
+
/**
|
|
9675
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9676
|
+
*/
|
|
9677
|
+
|
|
9678
|
+
/**
|
|
9679
|
+
* @@@
|
|
9680
|
+
*
|
|
9681
|
+
* @@@ .env
|
|
9682
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9683
|
+
*
|
|
9684
|
+
* It looks for environment variables:
|
|
9685
|
+
* - `process.env.OPENAI_API_KEY`
|
|
9686
|
+
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9687
|
+
* - ...
|
|
9688
|
+
*
|
|
9689
|
+
* @returns @@@
|
|
9690
|
+
* @public exported from `@promptbook/node`
|
|
9691
|
+
*/
|
|
9692
|
+
async function $provideLlmToolsConfigurationFromEnv() {
|
|
9693
|
+
if (!$isRunningInNode()) {
|
|
9694
|
+
throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
|
|
9695
|
+
}
|
|
9696
|
+
const envFilepath = await $provideEnvFilename();
|
|
9697
|
+
if (envFilepath !== null) {
|
|
9698
|
+
dotenv__namespace.config({ path: envFilepath });
|
|
9699
|
+
}
|
|
9593
9700
|
const llmToolsConfiguration = $llmToolsMetadataRegister
|
|
9594
9701
|
.list()
|
|
9595
9702
|
.map((metadata) => metadata.createConfigurationFromEnv(process.env))
|
|
@@ -9597,15 +9704,8 @@
|
|
|
9597
9704
|
return llmToolsConfiguration;
|
|
9598
9705
|
}
|
|
9599
9706
|
/**
|
|
9600
|
-
* TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
|
|
9601
|
-
* TODO: Add Azure OpenAI
|
|
9602
|
-
* TODO: [🧠][🍛]
|
|
9603
|
-
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
9604
9707
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9605
|
-
|
|
9606
|
-
* TODO: This should be maybe not under `_common` but under `utils`
|
|
9607
|
-
* TODO: [🧠][⚛] Maybe pass env as argument
|
|
9608
|
-
* TODO: [®] DRY Register logic */
|
|
9708
|
+
*/
|
|
9609
9709
|
|
|
9610
9710
|
/**
|
|
9611
9711
|
* @@@
|
|
@@ -9664,6 +9764,7 @@
|
|
|
9664
9764
|
* Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
|
|
9665
9765
|
*
|
|
9666
9766
|
* @@@ .env
|
|
9767
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9667
9768
|
*
|
|
9668
9769
|
* It looks for environment variables:
|
|
9669
9770
|
* - `process.env.OPENAI_API_KEY`
|
|
@@ -10197,9 +10298,7 @@
|
|
|
10197
10298
|
}
|
|
10198
10299
|
}
|
|
10199
10300
|
catch (error) {
|
|
10200
|
-
|
|
10201
|
-
throw error;
|
|
10202
|
-
}
|
|
10301
|
+
assertsError(error);
|
|
10203
10302
|
if (error instanceof ReferenceError) {
|
|
10204
10303
|
const undefinedName = error.message.split(' ')[0];
|
|
10205
10304
|
/*
|
|
@@ -10474,9 +10573,7 @@
|
|
|
10474
10573
|
// ---
|
|
10475
10574
|
}
|
|
10476
10575
|
catch (error) {
|
|
10477
|
-
|
|
10478
|
-
throw error;
|
|
10479
|
-
}
|
|
10576
|
+
assertsError(error);
|
|
10480
10577
|
// TODO: [7] DRY
|
|
10481
10578
|
const wrappedErrorMessage = spaceTrim__default["default"]((block) => `
|
|
10482
10579
|
${error.name} in pipeline ${fileName.split('\\').join('/')}:
|
|
@@ -10567,9 +10664,7 @@
|
|
|
10567
10664
|
}
|
|
10568
10665
|
}
|
|
10569
10666
|
catch (error) {
|
|
10570
|
-
|
|
10571
|
-
throw error;
|
|
10572
|
-
}
|
|
10667
|
+
assertsError(error);
|
|
10573
10668
|
// TODO: [7] DRY
|
|
10574
10669
|
const wrappedErrorMessage = spaceTrim__default["default"]((block) => `
|
|
10575
10670
|
${error.name} in pipeline ${fileName.split('\\').join('/')}:
|