@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/README.md
CHANGED
|
@@ -248,6 +248,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
|
|
|
248
248
|
|
|
249
249
|
|
|
250
250
|
|
|
251
|
+
## 🔒 Security
|
|
252
|
+
|
|
253
|
+
For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
|
|
254
|
+
|
|
251
255
|
## 📦 Packages _(for developers)_
|
|
252
256
|
|
|
253
257
|
This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -304,7 +308,7 @@ The following glossary is used to clarify certain concepts:
|
|
|
304
308
|
### General LLM / AI terms
|
|
305
309
|
|
|
306
310
|
- **Prompt drift** is a phenomenon where the AI model starts to generate outputs that are not aligned with the original prompt. This can happen due to the model's training data, the prompt's wording, or the model's architecture.
|
|
307
|
-
- **Pipeline, workflow or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.
|
|
311
|
+
- [**Pipeline, workflow scenario or chain** is a sequence of tasks that are executed in a specific order. In the context of AI, a pipeline can refer to a sequence of AI models that are used to process data.](https://github.com/webgptorg/promptbook/discussions/88)
|
|
308
312
|
- **Fine-tuning** is a process where a pre-trained AI model is further trained on a specific dataset to improve its performance on a specific task.
|
|
309
313
|
- **Zero-shot learning** is a machine learning paradigm where a model is trained to perform a task without any labeled examples. Instead, the model is provided with a description of the task and is expected to generate the correct output.
|
|
310
314
|
- **Few-shot learning** is a machine learning paradigm where a model is trained to perform a task with only a few labeled examples. This is in contrast to traditional machine learning, where models are trained on large datasets.
|
|
@@ -312,10 +316,6 @@ The following glossary is used to clarify certain concepts:
|
|
|
312
316
|
- **Retrieval-augmented generation** is a machine learning paradigm where a model generates text by retrieving relevant information from a large database of text. This approach combines the benefits of generative models and retrieval models.
|
|
313
317
|
- **Longtail** refers to non-common or rare events, items, or entities that are not well-represented in the training data of machine learning models. Longtail items are often challenging for models to predict accurately.
|
|
314
318
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
319
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
320
320
|
|
|
321
321
|
|
|
@@ -429,6 +429,8 @@ See [TODO.md](./TODO.md)
|
|
|
429
429
|
|
|
430
430
|
## 🖋️ Contributing
|
|
431
431
|
|
|
432
|
-
We are open to pull requests, feedback, and suggestions.
|
|
432
|
+
You can also ⭐ star the project, [follow us on GitHub](https://github.com/hejny) or [various other social networks](https://www.pavolhejny.com/contact/).We are open to [pull requests, feedback, and suggestions](./CONTRIBUTING.md).
|
|
433
|
+
|
|
434
|
+
## 📞 Support
|
|
433
435
|
|
|
434
|
-
|
|
436
|
+
If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
|
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-
|
|
33
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-30';
|
|
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
|
|
@@ -76,6 +76,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
|
76
76
|
* @public exported from `@promptbook/core`
|
|
77
77
|
*/
|
|
78
78
|
const ADMIN_GITHUB_NAME = 'hejny';
|
|
79
|
+
// <- TODO: [🐊] Pick the best claim
|
|
79
80
|
/**
|
|
80
81
|
* When the title is not provided, the default title is used
|
|
81
82
|
*
|
|
@@ -120,6 +121,7 @@ const VALUE_STRINGS = {
|
|
|
120
121
|
infinity: '(infinity; ∞)',
|
|
121
122
|
negativeInfinity: '(negative infinity; -∞)',
|
|
122
123
|
unserializable: '(unserializable value)',
|
|
124
|
+
circular: '(circular JSON)',
|
|
123
125
|
};
|
|
124
126
|
/**
|
|
125
127
|
* Small number limit
|
|
@@ -159,6 +161,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
159
161
|
*/
|
|
160
162
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
161
163
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
164
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
162
165
|
/**
|
|
163
166
|
* Where to store the temporary downloads
|
|
164
167
|
*
|
|
@@ -175,6 +178,15 @@ const DEFAULT_DOWNLOAD_CACHE_DIRNAME = './.promptbook/download-cache';
|
|
|
175
178
|
* @public exported from `@promptbook/core`
|
|
176
179
|
*/
|
|
177
180
|
const DEFAULT_SCRAPE_CACHE_DIRNAME = './.promptbook/scrape-cache';
|
|
181
|
+
/*
|
|
182
|
+
TODO: [🌃]
|
|
183
|
+
/**
|
|
184
|
+
* Id of application for the wizzard when using remote server
|
|
185
|
+
*
|
|
186
|
+
* @public exported from `@promptbook/core`
|
|
187
|
+
* /
|
|
188
|
+
ex-port const WIZZARD_APP_ID: string_app_id = 'wizzard';
|
|
189
|
+
*/
|
|
178
190
|
/**
|
|
179
191
|
* The name of the builded pipeline collection made by CLI `ptbk make` and for lookup in `createCollectionFromDirectory`
|
|
180
192
|
*
|
|
@@ -216,7 +228,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
216
228
|
true);
|
|
217
229
|
/**
|
|
218
230
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
219
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
231
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
220
232
|
*/
|
|
221
233
|
|
|
222
234
|
/**
|
|
@@ -329,6 +341,54 @@ function $deepFreeze(objectValue) {
|
|
|
329
341
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
330
342
|
*/
|
|
331
343
|
|
|
344
|
+
/**
|
|
345
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
346
|
+
*
|
|
347
|
+
* @public exported from `@promptbook/core`
|
|
348
|
+
*/
|
|
349
|
+
class WrappedError extends Error {
|
|
350
|
+
constructor(whatWasThrown) {
|
|
351
|
+
const tag = `[🤮]`;
|
|
352
|
+
console.error(tag, whatWasThrown);
|
|
353
|
+
super(spaceTrim$1(`
|
|
354
|
+
Non-Error object was thrown
|
|
355
|
+
|
|
356
|
+
Note: Look for ${tag} in the console for more details
|
|
357
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
358
|
+
`));
|
|
359
|
+
this.name = 'WrappedError';
|
|
360
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
366
|
+
*
|
|
367
|
+
* @param whatWasThrown Any object that was thrown
|
|
368
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
369
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
370
|
+
*
|
|
371
|
+
* @private within the repository
|
|
372
|
+
*/
|
|
373
|
+
function assertsError(whatWasThrown) {
|
|
374
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
375
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
376
|
+
const wrappedError = whatWasThrown;
|
|
377
|
+
throw wrappedError;
|
|
378
|
+
}
|
|
379
|
+
// Case 2: Handle unexpected errors
|
|
380
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
381
|
+
const unexpectedError = whatWasThrown;
|
|
382
|
+
throw unexpectedError;
|
|
383
|
+
}
|
|
384
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
385
|
+
if (whatWasThrown instanceof Error) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
389
|
+
throw new WrappedError(whatWasThrown);
|
|
390
|
+
}
|
|
391
|
+
|
|
332
392
|
/**
|
|
333
393
|
* Checks if the value is [🚉] serializable as JSON
|
|
334
394
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -420,9 +480,7 @@ function checkSerializableAsJson(options) {
|
|
|
420
480
|
JSON.stringify(value); // <- TODO: [0]
|
|
421
481
|
}
|
|
422
482
|
catch (error) {
|
|
423
|
-
|
|
424
|
-
throw error;
|
|
425
|
-
}
|
|
483
|
+
assertsError(error);
|
|
426
484
|
throw new UnexpectedError(spaceTrim((block) => `
|
|
427
485
|
\`${name}\` is not serializable
|
|
428
486
|
|
|
@@ -1117,9 +1175,7 @@ function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
|
1117
1175
|
return true;
|
|
1118
1176
|
}
|
|
1119
1177
|
catch (error) {
|
|
1120
|
-
|
|
1121
|
-
throw error;
|
|
1122
|
-
}
|
|
1178
|
+
assertsError(error);
|
|
1123
1179
|
if (error.message.includes('Unexpected token')) {
|
|
1124
1180
|
return false;
|
|
1125
1181
|
}
|
|
@@ -1651,7 +1707,7 @@ class PipelineExecutionError extends Error {
|
|
|
1651
1707
|
}
|
|
1652
1708
|
}
|
|
1653
1709
|
/**
|
|
1654
|
-
* TODO:
|
|
1710
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
1655
1711
|
*/
|
|
1656
1712
|
|
|
1657
1713
|
/**
|
|
@@ -1684,6 +1740,19 @@ class CsvFormatError extends AbstractFormatError {
|
|
|
1684
1740
|
}
|
|
1685
1741
|
}
|
|
1686
1742
|
|
|
1743
|
+
/**
|
|
1744
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
1745
|
+
*
|
|
1746
|
+
* @public exported from `@promptbook/core`
|
|
1747
|
+
*/
|
|
1748
|
+
class AuthenticationError extends Error {
|
|
1749
|
+
constructor(message) {
|
|
1750
|
+
super(message);
|
|
1751
|
+
this.name = 'AuthenticationError';
|
|
1752
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1687
1756
|
/**
|
|
1688
1757
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
1689
1758
|
*
|
|
@@ -1775,6 +1844,19 @@ class NotYetImplementedError extends Error {
|
|
|
1775
1844
|
}
|
|
1776
1845
|
}
|
|
1777
1846
|
|
|
1847
|
+
/**
|
|
1848
|
+
* Error thrown when a fetch request fails
|
|
1849
|
+
*
|
|
1850
|
+
* @public exported from `@promptbook/core`
|
|
1851
|
+
*/
|
|
1852
|
+
class PromptbookFetchError extends Error {
|
|
1853
|
+
constructor(message) {
|
|
1854
|
+
super(message);
|
|
1855
|
+
this.name = 'PromptbookFetchError';
|
|
1856
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1778
1860
|
/**
|
|
1779
1861
|
* Index of all custom errors
|
|
1780
1862
|
*
|
|
@@ -1795,7 +1877,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
1795
1877
|
PipelineExecutionError,
|
|
1796
1878
|
PipelineLogicError,
|
|
1797
1879
|
PipelineUrlError,
|
|
1880
|
+
AuthenticationError,
|
|
1881
|
+
PromptbookFetchError,
|
|
1798
1882
|
UnexpectedError,
|
|
1883
|
+
WrappedError,
|
|
1799
1884
|
// TODO: [🪑]> VersionMismatchError,
|
|
1800
1885
|
};
|
|
1801
1886
|
/**
|
|
@@ -1934,8 +2019,8 @@ function createTask(options) {
|
|
|
1934
2019
|
updatedAt = new Date();
|
|
1935
2020
|
errors.push(...executionResult.errors);
|
|
1936
2021
|
warnings.push(...executionResult.warnings);
|
|
1937
|
-
// <- TODO:
|
|
1938
|
-
// TODO: [🧠]
|
|
2022
|
+
// <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
|
|
2023
|
+
// TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
1939
2024
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
1940
2025
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
1941
2026
|
assertsTaskSuccessful(executionResult);
|
|
@@ -1945,6 +2030,7 @@ function createTask(options) {
|
|
|
1945
2030
|
partialResultSubject.next(executionResult);
|
|
1946
2031
|
}
|
|
1947
2032
|
catch (error) {
|
|
2033
|
+
assertsError(error);
|
|
1948
2034
|
status = 'ERROR';
|
|
1949
2035
|
errors.push(error);
|
|
1950
2036
|
partialResultSubject.error(error);
|
|
@@ -2011,6 +2097,10 @@ function serializeError(error) {
|
|
|
2011
2097
|
|
|
2012
2098
|
Cannot serialize error with name "${name}"
|
|
2013
2099
|
|
|
2100
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2101
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2102
|
+
|
|
2103
|
+
|
|
2014
2104
|
${block(stack || message)}
|
|
2015
2105
|
|
|
2016
2106
|
`));
|
|
@@ -2086,13 +2176,19 @@ function valueToString(value) {
|
|
|
2086
2176
|
return value.toISOString();
|
|
2087
2177
|
}
|
|
2088
2178
|
else {
|
|
2089
|
-
|
|
2179
|
+
try {
|
|
2180
|
+
return JSON.stringify(value);
|
|
2181
|
+
}
|
|
2182
|
+
catch (error) {
|
|
2183
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
2184
|
+
return VALUE_STRINGS.circular;
|
|
2185
|
+
}
|
|
2186
|
+
throw error;
|
|
2187
|
+
}
|
|
2090
2188
|
}
|
|
2091
2189
|
}
|
|
2092
2190
|
catch (error) {
|
|
2093
|
-
|
|
2094
|
-
throw error;
|
|
2095
|
-
}
|
|
2191
|
+
assertsError(error);
|
|
2096
2192
|
console.error(error);
|
|
2097
2193
|
return VALUE_STRINGS.unserializable;
|
|
2098
2194
|
}
|
|
@@ -2264,9 +2360,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
2264
2360
|
}
|
|
2265
2361
|
}
|
|
2266
2362
|
catch (error) {
|
|
2267
|
-
|
|
2268
|
-
throw error;
|
|
2269
|
-
}
|
|
2363
|
+
assertsError(error);
|
|
2270
2364
|
throw new ParseError(spaceTrim$1((block) => `
|
|
2271
2365
|
Can not extract variables from the script
|
|
2272
2366
|
${block(error.stack || error.message)}
|
|
@@ -2755,14 +2849,15 @@ class MultipleLlmExecutionTools {
|
|
|
2755
2849
|
}
|
|
2756
2850
|
}
|
|
2757
2851
|
catch (error) {
|
|
2758
|
-
|
|
2852
|
+
assertsError(error);
|
|
2853
|
+
if (error instanceof UnexpectedError) {
|
|
2759
2854
|
throw error;
|
|
2760
2855
|
}
|
|
2761
2856
|
errors.push({ llmExecutionTools, error });
|
|
2762
2857
|
}
|
|
2763
2858
|
}
|
|
2764
2859
|
if (errors.length === 1) {
|
|
2765
|
-
throw errors[0];
|
|
2860
|
+
throw errors[0].error;
|
|
2766
2861
|
}
|
|
2767
2862
|
else if (errors.length > 1) {
|
|
2768
2863
|
throw new PipelineExecutionError(
|
|
@@ -3619,9 +3714,7 @@ async function executeAttempts(options) {
|
|
|
3619
3714
|
break scripts;
|
|
3620
3715
|
}
|
|
3621
3716
|
catch (error) {
|
|
3622
|
-
|
|
3623
|
-
throw error;
|
|
3624
|
-
}
|
|
3717
|
+
assertsError(error);
|
|
3625
3718
|
if (error instanceof UnexpectedError) {
|
|
3626
3719
|
throw error;
|
|
3627
3720
|
}
|
|
@@ -3691,9 +3784,7 @@ async function executeAttempts(options) {
|
|
|
3691
3784
|
break scripts;
|
|
3692
3785
|
}
|
|
3693
3786
|
catch (error) {
|
|
3694
|
-
|
|
3695
|
-
throw error;
|
|
3696
|
-
}
|
|
3787
|
+
assertsError(error);
|
|
3697
3788
|
if (error instanceof UnexpectedError) {
|
|
3698
3789
|
throw error;
|
|
3699
3790
|
}
|
|
@@ -4314,9 +4405,7 @@ async function executePipeline(options) {
|
|
|
4314
4405
|
await Promise.all(resolving);
|
|
4315
4406
|
}
|
|
4316
4407
|
catch (error /* <- Note: [3] */) {
|
|
4317
|
-
|
|
4318
|
-
throw error;
|
|
4319
|
-
}
|
|
4408
|
+
assertsError(error);
|
|
4320
4409
|
// Note: No need to rethrow UnexpectedError
|
|
4321
4410
|
// if (error instanceof UnexpectedError) {
|
|
4322
4411
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|
|
@@ -5019,17 +5108,22 @@ function titleToName(value) {
|
|
|
5019
5108
|
/**
|
|
5020
5109
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5021
5110
|
*
|
|
5022
|
-
* @
|
|
5111
|
+
* @public exported from `@promptbook/core`
|
|
5023
5112
|
*/
|
|
5024
|
-
const
|
|
5113
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
5025
5114
|
try {
|
|
5026
|
-
return await fetch(
|
|
5115
|
+
return await fetch(urlOrRequest, init);
|
|
5027
5116
|
}
|
|
5028
5117
|
catch (error) {
|
|
5029
|
-
|
|
5030
|
-
|
|
5118
|
+
assertsError(error);
|
|
5119
|
+
let url;
|
|
5120
|
+
if (typeof urlOrRequest === 'string') {
|
|
5121
|
+
url = urlOrRequest;
|
|
5122
|
+
}
|
|
5123
|
+
else if (urlOrRequest instanceof Request) {
|
|
5124
|
+
url = urlOrRequest.url;
|
|
5031
5125
|
}
|
|
5032
|
-
throw new
|
|
5126
|
+
throw new PromptbookFetchError(spaceTrim((block) => `
|
|
5033
5127
|
Can not fetch "${url}"
|
|
5034
5128
|
|
|
5035
5129
|
Fetch error:
|
|
@@ -5050,7 +5144,7 @@ const scraperFetch = async (url, init) => {
|
|
|
5050
5144
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5051
5145
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
5052
5146
|
var _a;
|
|
5053
|
-
const { fetch =
|
|
5147
|
+
const { fetch = promptbookFetch } = tools;
|
|
5054
5148
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
5055
5149
|
let { name } = knowledgeSource;
|
|
5056
5150
|
const { rootDirname = null,
|
|
@@ -5252,9 +5346,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
5252
5346
|
knowledgePreparedUnflatten[index] = pieces;
|
|
5253
5347
|
}
|
|
5254
5348
|
catch (error) {
|
|
5255
|
-
|
|
5256
|
-
throw error;
|
|
5257
|
-
}
|
|
5349
|
+
assertsError(error);
|
|
5258
5350
|
console.warn(error);
|
|
5259
5351
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5260
5352
|
}
|
|
@@ -6052,6 +6144,8 @@ function parseNumber(value) {
|
|
|
6052
6144
|
*/
|
|
6053
6145
|
|
|
6054
6146
|
/**
|
|
6147
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
6148
|
+
import { assertsError } from '../../errors/assertsError';
|
|
6055
6149
|
* Parses the expect command
|
|
6056
6150
|
*
|
|
6057
6151
|
* @see `documentationUrl` for more details
|
|
@@ -6143,9 +6237,7 @@ const expectCommandParser = {
|
|
|
6143
6237
|
};
|
|
6144
6238
|
}
|
|
6145
6239
|
catch (error) {
|
|
6146
|
-
|
|
6147
|
-
throw error;
|
|
6148
|
-
}
|
|
6240
|
+
assertsError(error);
|
|
6149
6241
|
throw new ParseError(spaceTrim((block) => `
|
|
6150
6242
|
Invalid FORMAT command
|
|
6151
6243
|
${block(error.message)}:
|
|
@@ -9126,9 +9218,7 @@ async function locateAppOnLinux({ linuxWhich, }) {
|
|
|
9126
9218
|
return result.trim();
|
|
9127
9219
|
}
|
|
9128
9220
|
catch (error) {
|
|
9129
|
-
|
|
9130
|
-
throw error;
|
|
9131
|
-
}
|
|
9221
|
+
assertsError(error);
|
|
9132
9222
|
return null;
|
|
9133
9223
|
}
|
|
9134
9224
|
}
|
|
@@ -9206,9 +9296,7 @@ async function locateAppOnMacOs({ macOsName, }) {
|
|
|
9206
9296
|
return result.trim() + toExec;
|
|
9207
9297
|
}
|
|
9208
9298
|
catch (error) {
|
|
9209
|
-
|
|
9210
|
-
throw error;
|
|
9211
|
-
}
|
|
9299
|
+
assertsError(error);
|
|
9212
9300
|
return null;
|
|
9213
9301
|
}
|
|
9214
9302
|
}
|
|
@@ -9239,9 +9327,7 @@ async function locateAppOnWindows({ appName, windowsSuffix, }) {
|
|
|
9239
9327
|
throw new Error(`Can not locate app ${appName} on Windows.`);
|
|
9240
9328
|
}
|
|
9241
9329
|
catch (error) {
|
|
9242
|
-
|
|
9243
|
-
throw error;
|
|
9244
|
-
}
|
|
9330
|
+
assertsError(error);
|
|
9245
9331
|
return null;
|
|
9246
9332
|
}
|
|
9247
9333
|
}
|
|
@@ -9530,21 +9616,15 @@ function $registeredLlmToolsMessage() {
|
|
|
9530
9616
|
*/
|
|
9531
9617
|
|
|
9532
9618
|
/**
|
|
9533
|
-
*
|
|
9534
|
-
*
|
|
9535
|
-
* @@@ .env
|
|
9619
|
+
* Provides the path to the `.env` file
|
|
9536
9620
|
*
|
|
9537
|
-
*
|
|
9538
|
-
* - `process.env.OPENAI_API_KEY`
|
|
9539
|
-
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9540
|
-
* - ...
|
|
9621
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9541
9622
|
*
|
|
9542
|
-
* @
|
|
9543
|
-
* @public exported from `@promptbook/node`
|
|
9623
|
+
* @private within the repository - for CLI utils
|
|
9544
9624
|
*/
|
|
9545
|
-
async function $
|
|
9625
|
+
async function $provideEnvFilename() {
|
|
9546
9626
|
if (!$isRunningInNode()) {
|
|
9547
|
-
throw new EnvironmentMismatchError('Function `$
|
|
9627
|
+
throw new EnvironmentMismatchError('Function `$provideEnvFilename` works only in Node.js environment');
|
|
9548
9628
|
}
|
|
9549
9629
|
const envFilePatterns = [
|
|
9550
9630
|
'.env',
|
|
@@ -9564,8 +9644,7 @@ async function $provideLlmToolsConfigurationFromEnv() {
|
|
|
9564
9644
|
const envFilename = join(rootDirname, pattern);
|
|
9565
9645
|
if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
|
|
9566
9646
|
$setUsedEnvFilename(envFilename);
|
|
9567
|
-
|
|
9568
|
-
break up_to_root;
|
|
9647
|
+
return envFilename;
|
|
9569
9648
|
}
|
|
9570
9649
|
}
|
|
9571
9650
|
if (isRootPath(rootDirname)) {
|
|
@@ -9574,6 +9653,34 @@ async function $provideLlmToolsConfigurationFromEnv() {
|
|
|
9574
9653
|
// Note: If the directory does not exist, try the parent directory
|
|
9575
9654
|
rootDirname = join(rootDirname, '..');
|
|
9576
9655
|
}
|
|
9656
|
+
return null;
|
|
9657
|
+
}
|
|
9658
|
+
/**
|
|
9659
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9660
|
+
*/
|
|
9661
|
+
|
|
9662
|
+
/**
|
|
9663
|
+
* @@@
|
|
9664
|
+
*
|
|
9665
|
+
* @@@ .env
|
|
9666
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9667
|
+
*
|
|
9668
|
+
* It looks for environment variables:
|
|
9669
|
+
* - `process.env.OPENAI_API_KEY`
|
|
9670
|
+
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9671
|
+
* - ...
|
|
9672
|
+
*
|
|
9673
|
+
* @returns @@@
|
|
9674
|
+
* @public exported from `@promptbook/node`
|
|
9675
|
+
*/
|
|
9676
|
+
async function $provideLlmToolsConfigurationFromEnv() {
|
|
9677
|
+
if (!$isRunningInNode()) {
|
|
9678
|
+
throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
|
|
9679
|
+
}
|
|
9680
|
+
const envFilepath = await $provideEnvFilename();
|
|
9681
|
+
if (envFilepath !== null) {
|
|
9682
|
+
dotenv.config({ path: envFilepath });
|
|
9683
|
+
}
|
|
9577
9684
|
const llmToolsConfiguration = $llmToolsMetadataRegister
|
|
9578
9685
|
.list()
|
|
9579
9686
|
.map((metadata) => metadata.createConfigurationFromEnv(process.env))
|
|
@@ -9581,15 +9688,8 @@ async function $provideLlmToolsConfigurationFromEnv() {
|
|
|
9581
9688
|
return llmToolsConfiguration;
|
|
9582
9689
|
}
|
|
9583
9690
|
/**
|
|
9584
|
-
* TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
|
|
9585
|
-
* TODO: Add Azure OpenAI
|
|
9586
|
-
* TODO: [🧠][🍛]
|
|
9587
|
-
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
9588
9691
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9589
|
-
|
|
9590
|
-
* TODO: This should be maybe not under `_common` but under `utils`
|
|
9591
|
-
* TODO: [🧠][⚛] Maybe pass env as argument
|
|
9592
|
-
* TODO: [®] DRY Register logic */
|
|
9692
|
+
*/
|
|
9593
9693
|
|
|
9594
9694
|
/**
|
|
9595
9695
|
* @@@
|
|
@@ -9648,6 +9748,7 @@ function createLlmToolsFromConfiguration(configuration, options = {}) {
|
|
|
9648
9748
|
* Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
|
|
9649
9749
|
*
|
|
9650
9750
|
* @@@ .env
|
|
9751
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9651
9752
|
*
|
|
9652
9753
|
* It looks for environment variables:
|
|
9653
9754
|
* - `process.env.OPENAI_API_KEY`
|
|
@@ -10181,9 +10282,7 @@ class JavascriptEvalExecutionTools {
|
|
|
10181
10282
|
}
|
|
10182
10283
|
}
|
|
10183
10284
|
catch (error) {
|
|
10184
|
-
|
|
10185
|
-
throw error;
|
|
10186
|
-
}
|
|
10285
|
+
assertsError(error);
|
|
10187
10286
|
if (error instanceof ReferenceError) {
|
|
10188
10287
|
const undefinedName = error.message.split(' ')[0];
|
|
10189
10288
|
/*
|
|
@@ -10458,9 +10557,7 @@ async function createCollectionFromDirectory(rootPath, tools, options) {
|
|
|
10458
10557
|
// ---
|
|
10459
10558
|
}
|
|
10460
10559
|
catch (error) {
|
|
10461
|
-
|
|
10462
|
-
throw error;
|
|
10463
|
-
}
|
|
10560
|
+
assertsError(error);
|
|
10464
10561
|
// TODO: [7] DRY
|
|
10465
10562
|
const wrappedErrorMessage = spaceTrim((block) => `
|
|
10466
10563
|
${error.name} in pipeline ${fileName.split('\\').join('/')}:
|
|
@@ -10551,9 +10648,7 @@ async function createCollectionFromDirectory(rootPath, tools, options) {
|
|
|
10551
10648
|
}
|
|
10552
10649
|
}
|
|
10553
10650
|
catch (error) {
|
|
10554
|
-
|
|
10555
|
-
throw error;
|
|
10556
|
-
}
|
|
10651
|
+
assertsError(error);
|
|
10557
10652
|
// TODO: [7] DRY
|
|
10558
10653
|
const wrappedErrorMessage = spaceTrim((block) => `
|
|
10559
10654
|
${error.name} in pipeline ${fileName.split('\\').join('/')}:
|