@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.
- package/README.md +9 -11
- package/esm/index.es.js +200 -84
- 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 +12 -4
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -6
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +24 -14
- package/esm/typings/src/_packages/utils.index.d.ts +4 -0
- package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
- 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 +10 -19
- package/esm/typings/src/errors/0-index.d.ts +8 -2
- 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/formats/csv/utils/isValidCsvString.d.ts +9 -0
- package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
- package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
- package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
- 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 +15 -4
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -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} +9 -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 +1 -2
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +2 -2
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +57 -38
- 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 +26 -0
- package/package.json +9 -5
- package/umd/index.umd.js +200 -84
- 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
|
@@ -23,10 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
<blockquote style="color: #ff8811">
|
|
27
|
-
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
-
</blockquote>
|
|
29
|
-
|
|
30
26
|
## 📦 Package `@promptbook/node`
|
|
31
27
|
|
|
32
28
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -248,6 +244,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
|
|
|
248
244
|
|
|
249
245
|
|
|
250
246
|
|
|
247
|
+
## 🔒 Security
|
|
248
|
+
|
|
249
|
+
For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
|
|
250
|
+
|
|
251
251
|
## 📦 Packages _(for developers)_
|
|
252
252
|
|
|
253
253
|
This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -304,7 +304,7 @@ The following glossary is used to clarify certain concepts:
|
|
|
304
304
|
### General LLM / AI terms
|
|
305
305
|
|
|
306
306
|
- **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.
|
|
307
|
+
- [**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
308
|
- **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
309
|
- **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
310
|
- **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 +312,6 @@ The following glossary is used to clarify certain concepts:
|
|
|
312
312
|
- **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
313
|
- **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
314
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
315
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
320
316
|
|
|
321
317
|
|
|
@@ -429,6 +425,8 @@ See [TODO.md](./TODO.md)
|
|
|
429
425
|
|
|
430
426
|
## 🖋️ Contributing
|
|
431
427
|
|
|
432
|
-
We are open to pull requests, feedback, and suggestions.
|
|
428
|
+
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).
|
|
429
|
+
|
|
430
|
+
## 📞 Support
|
|
433
431
|
|
|
434
|
-
|
|
432
|
+
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';
|
|
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,7 +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`
|
|
162
|
-
// TODO:
|
|
164
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
163
165
|
/**
|
|
164
166
|
* Where to store the temporary downloads
|
|
165
167
|
*
|
|
@@ -339,6 +341,54 @@ function $deepFreeze(objectValue) {
|
|
|
339
341
|
* TODO: [🧠] Is there a way how to meaningfully test this utility
|
|
340
342
|
*/
|
|
341
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
|
+
|
|
342
392
|
/**
|
|
343
393
|
* Checks if the value is [🚉] serializable as JSON
|
|
344
394
|
* If not, throws an UnexpectedError with a rich error message and tracking
|
|
@@ -430,9 +480,7 @@ function checkSerializableAsJson(options) {
|
|
|
430
480
|
JSON.stringify(value); // <- TODO: [0]
|
|
431
481
|
}
|
|
432
482
|
catch (error) {
|
|
433
|
-
|
|
434
|
-
throw error;
|
|
435
|
-
}
|
|
483
|
+
assertsError(error);
|
|
436
484
|
throw new UnexpectedError(spaceTrim((block) => `
|
|
437
485
|
\`${name}\` is not serializable
|
|
438
486
|
|
|
@@ -1119,6 +1167,9 @@ function isValidFilePath(filename) {
|
|
|
1119
1167
|
/**
|
|
1120
1168
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1121
1169
|
*
|
|
1170
|
+
* @param value The string to check
|
|
1171
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
1172
|
+
*
|
|
1122
1173
|
* @public exported from `@promptbook/utils`
|
|
1123
1174
|
*/
|
|
1124
1175
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
@@ -1127,9 +1178,7 @@ function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
|
1127
1178
|
return true;
|
|
1128
1179
|
}
|
|
1129
1180
|
catch (error) {
|
|
1130
|
-
|
|
1131
|
-
throw error;
|
|
1132
|
-
}
|
|
1181
|
+
assertsError(error);
|
|
1133
1182
|
if (error.message.includes('Unexpected token')) {
|
|
1134
1183
|
return false;
|
|
1135
1184
|
}
|
|
@@ -1661,7 +1710,7 @@ class PipelineExecutionError extends Error {
|
|
|
1661
1710
|
}
|
|
1662
1711
|
}
|
|
1663
1712
|
/**
|
|
1664
|
-
* TODO:
|
|
1713
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
1665
1714
|
*/
|
|
1666
1715
|
|
|
1667
1716
|
/**
|
|
@@ -1798,6 +1847,19 @@ class NotYetImplementedError extends Error {
|
|
|
1798
1847
|
}
|
|
1799
1848
|
}
|
|
1800
1849
|
|
|
1850
|
+
/**
|
|
1851
|
+
* Error thrown when a fetch request fails
|
|
1852
|
+
*
|
|
1853
|
+
* @public exported from `@promptbook/core`
|
|
1854
|
+
*/
|
|
1855
|
+
class PromptbookFetchError extends Error {
|
|
1856
|
+
constructor(message) {
|
|
1857
|
+
super(message);
|
|
1858
|
+
this.name = 'PromptbookFetchError';
|
|
1859
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1801
1863
|
/**
|
|
1802
1864
|
* Index of all custom errors
|
|
1803
1865
|
*
|
|
@@ -1818,7 +1880,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
1818
1880
|
PipelineExecutionError,
|
|
1819
1881
|
PipelineLogicError,
|
|
1820
1882
|
PipelineUrlError,
|
|
1883
|
+
AuthenticationError,
|
|
1884
|
+
PromptbookFetchError,
|
|
1821
1885
|
UnexpectedError,
|
|
1886
|
+
WrappedError,
|
|
1822
1887
|
// TODO: [🪑]> VersionMismatchError,
|
|
1823
1888
|
};
|
|
1824
1889
|
/**
|
|
@@ -1835,7 +1900,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
|
|
|
1835
1900
|
TypeError,
|
|
1836
1901
|
URIError,
|
|
1837
1902
|
AggregateError,
|
|
1838
|
-
AuthenticationError,
|
|
1839
1903
|
/*
|
|
1840
1904
|
Note: Not widely supported
|
|
1841
1905
|
> InternalError,
|
|
@@ -1958,8 +2022,8 @@ function createTask(options) {
|
|
|
1958
2022
|
updatedAt = new Date();
|
|
1959
2023
|
errors.push(...executionResult.errors);
|
|
1960
2024
|
warnings.push(...executionResult.warnings);
|
|
1961
|
-
// <- TODO:
|
|
1962
|
-
// TODO: [🧠]
|
|
2025
|
+
// <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
|
|
2026
|
+
// TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
1963
2027
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
1964
2028
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
1965
2029
|
assertsTaskSuccessful(executionResult);
|
|
@@ -1969,6 +2033,7 @@ function createTask(options) {
|
|
|
1969
2033
|
partialResultSubject.next(executionResult);
|
|
1970
2034
|
}
|
|
1971
2035
|
catch (error) {
|
|
2036
|
+
assertsError(error);
|
|
1972
2037
|
status = 'ERROR';
|
|
1973
2038
|
errors.push(error);
|
|
1974
2039
|
partialResultSubject.error(error);
|
|
@@ -2114,13 +2179,19 @@ function valueToString(value) {
|
|
|
2114
2179
|
return value.toISOString();
|
|
2115
2180
|
}
|
|
2116
2181
|
else {
|
|
2117
|
-
|
|
2182
|
+
try {
|
|
2183
|
+
return JSON.stringify(value);
|
|
2184
|
+
}
|
|
2185
|
+
catch (error) {
|
|
2186
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
2187
|
+
return VALUE_STRINGS.circular;
|
|
2188
|
+
}
|
|
2189
|
+
throw error;
|
|
2190
|
+
}
|
|
2118
2191
|
}
|
|
2119
2192
|
}
|
|
2120
2193
|
catch (error) {
|
|
2121
|
-
|
|
2122
|
-
throw error;
|
|
2123
|
-
}
|
|
2194
|
+
assertsError(error);
|
|
2124
2195
|
console.error(error);
|
|
2125
2196
|
return VALUE_STRINGS.unserializable;
|
|
2126
2197
|
}
|
|
@@ -2292,9 +2363,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
2292
2363
|
}
|
|
2293
2364
|
}
|
|
2294
2365
|
catch (error) {
|
|
2295
|
-
|
|
2296
|
-
throw error;
|
|
2297
|
-
}
|
|
2366
|
+
assertsError(error);
|
|
2298
2367
|
throw new ParseError(spaceTrim$1((block) => `
|
|
2299
2368
|
Can not extract variables from the script
|
|
2300
2369
|
${block(error.stack || error.message)}
|
|
@@ -2413,6 +2482,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
2413
2482
|
// encoding: 'utf-8',
|
|
2414
2483
|
});
|
|
2415
2484
|
|
|
2485
|
+
/**
|
|
2486
|
+
* Function to check if a string is valid CSV
|
|
2487
|
+
*
|
|
2488
|
+
* @param value The string to check
|
|
2489
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
2490
|
+
*
|
|
2491
|
+
* @public exported from `@promptbook/utils`
|
|
2492
|
+
*/
|
|
2493
|
+
function isValidCsvString(value) {
|
|
2494
|
+
try {
|
|
2495
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
2496
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
2497
|
+
return true;
|
|
2498
|
+
}
|
|
2499
|
+
return false;
|
|
2500
|
+
}
|
|
2501
|
+
catch (error) {
|
|
2502
|
+
assertsError(error);
|
|
2503
|
+
return false;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2416
2507
|
/**
|
|
2417
2508
|
* Definition for CSV spreadsheet
|
|
2418
2509
|
*
|
|
@@ -2423,7 +2514,7 @@ const CsvFormatDefinition = {
|
|
|
2423
2514
|
formatName: 'CSV',
|
|
2424
2515
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
2425
2516
|
isValid(value, settings, schema) {
|
|
2426
|
-
return
|
|
2517
|
+
return isValidCsvString(value);
|
|
2427
2518
|
},
|
|
2428
2519
|
canBeValid(partialValue, settings, schema) {
|
|
2429
2520
|
return true;
|
|
@@ -2577,6 +2668,30 @@ const TextFormatDefinition = {
|
|
|
2577
2668
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
2578
2669
|
*/
|
|
2579
2670
|
|
|
2671
|
+
/**
|
|
2672
|
+
* Function to check if a string is valid XML
|
|
2673
|
+
*
|
|
2674
|
+
* @param value
|
|
2675
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
2676
|
+
*
|
|
2677
|
+
* @public exported from `@promptbook/utils`
|
|
2678
|
+
*/
|
|
2679
|
+
function isValidXmlString(value) {
|
|
2680
|
+
try {
|
|
2681
|
+
const parser = new DOMParser();
|
|
2682
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
2683
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
2684
|
+
if (parserError.length > 0) {
|
|
2685
|
+
return false;
|
|
2686
|
+
}
|
|
2687
|
+
return true;
|
|
2688
|
+
}
|
|
2689
|
+
catch (error) {
|
|
2690
|
+
assertsError(error);
|
|
2691
|
+
return false;
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2580
2695
|
/**
|
|
2581
2696
|
* Definition for XML format
|
|
2582
2697
|
*
|
|
@@ -2586,7 +2701,7 @@ const XmlFormatDefinition = {
|
|
|
2586
2701
|
formatName: 'XML',
|
|
2587
2702
|
mimeType: 'application/xml',
|
|
2588
2703
|
isValid(value, settings, schema) {
|
|
2589
|
-
return
|
|
2704
|
+
return isValidXmlString(value);
|
|
2590
2705
|
},
|
|
2591
2706
|
canBeValid(partialValue, settings, schema) {
|
|
2592
2707
|
return true;
|
|
@@ -2783,14 +2898,15 @@ class MultipleLlmExecutionTools {
|
|
|
2783
2898
|
}
|
|
2784
2899
|
}
|
|
2785
2900
|
catch (error) {
|
|
2786
|
-
|
|
2901
|
+
assertsError(error);
|
|
2902
|
+
if (error instanceof UnexpectedError) {
|
|
2787
2903
|
throw error;
|
|
2788
2904
|
}
|
|
2789
2905
|
errors.push({ llmExecutionTools, error });
|
|
2790
2906
|
}
|
|
2791
2907
|
}
|
|
2792
2908
|
if (errors.length === 1) {
|
|
2793
|
-
throw errors[0];
|
|
2909
|
+
throw errors[0].error;
|
|
2794
2910
|
}
|
|
2795
2911
|
else if (errors.length > 1) {
|
|
2796
2912
|
throw new PipelineExecutionError(
|
|
@@ -3647,9 +3763,7 @@ async function executeAttempts(options) {
|
|
|
3647
3763
|
break scripts;
|
|
3648
3764
|
}
|
|
3649
3765
|
catch (error) {
|
|
3650
|
-
|
|
3651
|
-
throw error;
|
|
3652
|
-
}
|
|
3766
|
+
assertsError(error);
|
|
3653
3767
|
if (error instanceof UnexpectedError) {
|
|
3654
3768
|
throw error;
|
|
3655
3769
|
}
|
|
@@ -3719,9 +3833,7 @@ async function executeAttempts(options) {
|
|
|
3719
3833
|
break scripts;
|
|
3720
3834
|
}
|
|
3721
3835
|
catch (error) {
|
|
3722
|
-
|
|
3723
|
-
throw error;
|
|
3724
|
-
}
|
|
3836
|
+
assertsError(error);
|
|
3725
3837
|
if (error instanceof UnexpectedError) {
|
|
3726
3838
|
throw error;
|
|
3727
3839
|
}
|
|
@@ -4342,9 +4454,7 @@ async function executePipeline(options) {
|
|
|
4342
4454
|
await Promise.all(resolving);
|
|
4343
4455
|
}
|
|
4344
4456
|
catch (error /* <- Note: [3] */) {
|
|
4345
|
-
|
|
4346
|
-
throw error;
|
|
4347
|
-
}
|
|
4457
|
+
assertsError(error);
|
|
4348
4458
|
// Note: No need to rethrow UnexpectedError
|
|
4349
4459
|
// if (error instanceof UnexpectedError) {
|
|
4350
4460
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|
|
@@ -5047,17 +5157,22 @@ function titleToName(value) {
|
|
|
5047
5157
|
/**
|
|
5048
5158
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
5049
5159
|
*
|
|
5050
|
-
* @
|
|
5160
|
+
* @public exported from `@promptbook/core`
|
|
5051
5161
|
*/
|
|
5052
|
-
const
|
|
5162
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
5053
5163
|
try {
|
|
5054
|
-
return await fetch(
|
|
5164
|
+
return await fetch(urlOrRequest, init);
|
|
5055
5165
|
}
|
|
5056
5166
|
catch (error) {
|
|
5057
|
-
|
|
5058
|
-
|
|
5167
|
+
assertsError(error);
|
|
5168
|
+
let url;
|
|
5169
|
+
if (typeof urlOrRequest === 'string') {
|
|
5170
|
+
url = urlOrRequest;
|
|
5059
5171
|
}
|
|
5060
|
-
|
|
5172
|
+
else if (urlOrRequest instanceof Request) {
|
|
5173
|
+
url = urlOrRequest.url;
|
|
5174
|
+
}
|
|
5175
|
+
throw new PromptbookFetchError(spaceTrim((block) => `
|
|
5061
5176
|
Can not fetch "${url}"
|
|
5062
5177
|
|
|
5063
5178
|
Fetch error:
|
|
@@ -5078,7 +5193,7 @@ const scraperFetch = async (url, init) => {
|
|
|
5078
5193
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
5079
5194
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
5080
5195
|
var _a;
|
|
5081
|
-
const { fetch =
|
|
5196
|
+
const { fetch = promptbookFetch } = tools;
|
|
5082
5197
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
5083
5198
|
let { name } = knowledgeSource;
|
|
5084
5199
|
const { rootDirname = null,
|
|
@@ -5280,9 +5395,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
5280
5395
|
knowledgePreparedUnflatten[index] = pieces;
|
|
5281
5396
|
}
|
|
5282
5397
|
catch (error) {
|
|
5283
|
-
|
|
5284
|
-
throw error;
|
|
5285
|
-
}
|
|
5398
|
+
assertsError(error);
|
|
5286
5399
|
console.warn(error);
|
|
5287
5400
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5288
5401
|
}
|
|
@@ -6080,6 +6193,8 @@ function parseNumber(value) {
|
|
|
6080
6193
|
*/
|
|
6081
6194
|
|
|
6082
6195
|
/**
|
|
6196
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
6197
|
+
import { assertsError } from '../../errors/assertsError';
|
|
6083
6198
|
* Parses the expect command
|
|
6084
6199
|
*
|
|
6085
6200
|
* @see `documentationUrl` for more details
|
|
@@ -6171,9 +6286,7 @@ const expectCommandParser = {
|
|
|
6171
6286
|
};
|
|
6172
6287
|
}
|
|
6173
6288
|
catch (error) {
|
|
6174
|
-
|
|
6175
|
-
throw error;
|
|
6176
|
-
}
|
|
6289
|
+
assertsError(error);
|
|
6177
6290
|
throw new ParseError(spaceTrim((block) => `
|
|
6178
6291
|
Invalid FORMAT command
|
|
6179
6292
|
${block(error.message)}:
|
|
@@ -9154,9 +9267,7 @@ async function locateAppOnLinux({ linuxWhich, }) {
|
|
|
9154
9267
|
return result.trim();
|
|
9155
9268
|
}
|
|
9156
9269
|
catch (error) {
|
|
9157
|
-
|
|
9158
|
-
throw error;
|
|
9159
|
-
}
|
|
9270
|
+
assertsError(error);
|
|
9160
9271
|
return null;
|
|
9161
9272
|
}
|
|
9162
9273
|
}
|
|
@@ -9234,9 +9345,7 @@ async function locateAppOnMacOs({ macOsName, }) {
|
|
|
9234
9345
|
return result.trim() + toExec;
|
|
9235
9346
|
}
|
|
9236
9347
|
catch (error) {
|
|
9237
|
-
|
|
9238
|
-
throw error;
|
|
9239
|
-
}
|
|
9348
|
+
assertsError(error);
|
|
9240
9349
|
return null;
|
|
9241
9350
|
}
|
|
9242
9351
|
}
|
|
@@ -9267,9 +9376,7 @@ async function locateAppOnWindows({ appName, windowsSuffix, }) {
|
|
|
9267
9376
|
throw new Error(`Can not locate app ${appName} on Windows.`);
|
|
9268
9377
|
}
|
|
9269
9378
|
catch (error) {
|
|
9270
|
-
|
|
9271
|
-
throw error;
|
|
9272
|
-
}
|
|
9379
|
+
assertsError(error);
|
|
9273
9380
|
return null;
|
|
9274
9381
|
}
|
|
9275
9382
|
}
|
|
@@ -9558,21 +9665,15 @@ function $registeredLlmToolsMessage() {
|
|
|
9558
9665
|
*/
|
|
9559
9666
|
|
|
9560
9667
|
/**
|
|
9561
|
-
*
|
|
9562
|
-
*
|
|
9563
|
-
* @@@ .env
|
|
9668
|
+
* Provides the path to the `.env` file
|
|
9564
9669
|
*
|
|
9565
|
-
*
|
|
9566
|
-
* - `process.env.OPENAI_API_KEY`
|
|
9567
|
-
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9568
|
-
* - ...
|
|
9670
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9569
9671
|
*
|
|
9570
|
-
* @
|
|
9571
|
-
* @public exported from `@promptbook/node`
|
|
9672
|
+
* @private within the repository - for CLI utils
|
|
9572
9673
|
*/
|
|
9573
|
-
async function $
|
|
9674
|
+
async function $provideEnvFilename() {
|
|
9574
9675
|
if (!$isRunningInNode()) {
|
|
9575
|
-
throw new EnvironmentMismatchError('Function `$
|
|
9676
|
+
throw new EnvironmentMismatchError('Function `$provideEnvFilename` works only in Node.js environment');
|
|
9576
9677
|
}
|
|
9577
9678
|
const envFilePatterns = [
|
|
9578
9679
|
'.env',
|
|
@@ -9592,8 +9693,7 @@ async function $provideLlmToolsConfigurationFromEnv() {
|
|
|
9592
9693
|
const envFilename = join(rootDirname, pattern);
|
|
9593
9694
|
if (await isFileExisting(envFilename, $provideFilesystemForNode())) {
|
|
9594
9695
|
$setUsedEnvFilename(envFilename);
|
|
9595
|
-
|
|
9596
|
-
break up_to_root;
|
|
9696
|
+
return envFilename;
|
|
9597
9697
|
}
|
|
9598
9698
|
}
|
|
9599
9699
|
if (isRootPath(rootDirname)) {
|
|
@@ -9602,6 +9702,34 @@ async function $provideLlmToolsConfigurationFromEnv() {
|
|
|
9602
9702
|
// Note: If the directory does not exist, try the parent directory
|
|
9603
9703
|
rootDirname = join(rootDirname, '..');
|
|
9604
9704
|
}
|
|
9705
|
+
return null;
|
|
9706
|
+
}
|
|
9707
|
+
/**
|
|
9708
|
+
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9709
|
+
*/
|
|
9710
|
+
|
|
9711
|
+
/**
|
|
9712
|
+
* @@@
|
|
9713
|
+
*
|
|
9714
|
+
* @@@ .env
|
|
9715
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9716
|
+
*
|
|
9717
|
+
* It looks for environment variables:
|
|
9718
|
+
* - `process.env.OPENAI_API_KEY`
|
|
9719
|
+
* - `process.env.ANTHROPIC_CLAUDE_API_KEY`
|
|
9720
|
+
* - ...
|
|
9721
|
+
*
|
|
9722
|
+
* @returns @@@
|
|
9723
|
+
* @public exported from `@promptbook/node`
|
|
9724
|
+
*/
|
|
9725
|
+
async function $provideLlmToolsConfigurationFromEnv() {
|
|
9726
|
+
if (!$isRunningInNode()) {
|
|
9727
|
+
throw new EnvironmentMismatchError('Function `$provideLlmToolsFromEnv` works only in Node.js environment');
|
|
9728
|
+
}
|
|
9729
|
+
const envFilepath = await $provideEnvFilename();
|
|
9730
|
+
if (envFilepath !== null) {
|
|
9731
|
+
dotenv.config({ path: envFilepath });
|
|
9732
|
+
}
|
|
9605
9733
|
const llmToolsConfiguration = $llmToolsMetadataRegister
|
|
9606
9734
|
.list()
|
|
9607
9735
|
.map((metadata) => metadata.createConfigurationFromEnv(process.env))
|
|
@@ -9609,15 +9737,8 @@ async function $provideLlmToolsConfigurationFromEnv() {
|
|
|
9609
9737
|
return llmToolsConfiguration;
|
|
9610
9738
|
}
|
|
9611
9739
|
/**
|
|
9612
|
-
* TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
|
|
9613
|
-
* TODO: Add Azure OpenAI
|
|
9614
|
-
* TODO: [🧠][🍛]
|
|
9615
|
-
* TODO: [🧠] Is there some meaningfull way how to test this util
|
|
9616
9740
|
* Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
|
|
9617
|
-
|
|
9618
|
-
* TODO: This should be maybe not under `_common` but under `utils`
|
|
9619
|
-
* TODO: [🧠][⚛] Maybe pass env as argument
|
|
9620
|
-
* TODO: [®] DRY Register logic */
|
|
9741
|
+
*/
|
|
9621
9742
|
|
|
9622
9743
|
/**
|
|
9623
9744
|
* @@@
|
|
@@ -9676,6 +9797,7 @@ function createLlmToolsFromConfiguration(configuration, options = {}) {
|
|
|
9676
9797
|
* Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
|
|
9677
9798
|
*
|
|
9678
9799
|
* @@@ .env
|
|
9800
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file
|
|
9679
9801
|
*
|
|
9680
9802
|
* It looks for environment variables:
|
|
9681
9803
|
* - `process.env.OPENAI_API_KEY`
|
|
@@ -10209,9 +10331,7 @@ class JavascriptEvalExecutionTools {
|
|
|
10209
10331
|
}
|
|
10210
10332
|
}
|
|
10211
10333
|
catch (error) {
|
|
10212
|
-
|
|
10213
|
-
throw error;
|
|
10214
|
-
}
|
|
10334
|
+
assertsError(error);
|
|
10215
10335
|
if (error instanceof ReferenceError) {
|
|
10216
10336
|
const undefinedName = error.message.split(' ')[0];
|
|
10217
10337
|
/*
|
|
@@ -10486,9 +10606,7 @@ async function createCollectionFromDirectory(rootPath, tools, options) {
|
|
|
10486
10606
|
// ---
|
|
10487
10607
|
}
|
|
10488
10608
|
catch (error) {
|
|
10489
|
-
|
|
10490
|
-
throw error;
|
|
10491
|
-
}
|
|
10609
|
+
assertsError(error);
|
|
10492
10610
|
// TODO: [7] DRY
|
|
10493
10611
|
const wrappedErrorMessage = spaceTrim((block) => `
|
|
10494
10612
|
${error.name} in pipeline ${fileName.split('\\').join('/')}:
|
|
@@ -10579,9 +10697,7 @@ async function createCollectionFromDirectory(rootPath, tools, options) {
|
|
|
10579
10697
|
}
|
|
10580
10698
|
}
|
|
10581
10699
|
catch (error) {
|
|
10582
|
-
|
|
10583
|
-
throw error;
|
|
10584
|
-
}
|
|
10700
|
+
assertsError(error);
|
|
10585
10701
|
// TODO: [7] DRY
|
|
10586
10702
|
const wrappedErrorMessage = spaceTrim((block) => `
|
|
10587
10703
|
${error.name} in pipeline ${fileName.split('\\').join('/')}:
|