@promptbook/documents 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 +155 -42
- 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 +8 -4
- package/umd/index.umd.js +155 -42
- 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/documents`
|
|
31
27
|
|
|
32
28
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -247,6 +243,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
|
|
|
247
243
|
|
|
248
244
|
|
|
249
245
|
|
|
246
|
+
## 🔒 Security
|
|
247
|
+
|
|
248
|
+
For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
|
|
249
|
+
|
|
250
250
|
## 📦 Packages _(for developers)_
|
|
251
251
|
|
|
252
252
|
This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -303,7 +303,7 @@ The following glossary is used to clarify certain concepts:
|
|
|
303
303
|
### General LLM / AI terms
|
|
304
304
|
|
|
305
305
|
- **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.
|
|
306
|
-
- **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.
|
|
306
|
+
- [**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)
|
|
307
307
|
- **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.
|
|
308
308
|
- **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.
|
|
309
309
|
- **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.
|
|
@@ -311,10 +311,6 @@ The following glossary is used to clarify certain concepts:
|
|
|
311
311
|
- **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.
|
|
312
312
|
- **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.
|
|
313
313
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
314
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
319
315
|
|
|
320
316
|
|
|
@@ -428,6 +424,8 @@ See [TODO.md](./TODO.md)
|
|
|
428
424
|
|
|
429
425
|
## 🖋️ Contributing
|
|
430
426
|
|
|
431
|
-
We are open to pull requests, feedback, and suggestions.
|
|
427
|
+
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).
|
|
428
|
+
|
|
429
|
+
## 📞 Support
|
|
432
430
|
|
|
433
|
-
|
|
431
|
+
If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
|
package/esm/index.es.js
CHANGED
|
@@ -28,7 +28,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
28
28
|
* @generated
|
|
29
29
|
* @see https://github.com/webgptorg/promptbook
|
|
30
30
|
*/
|
|
31
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0
|
|
31
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0';
|
|
32
32
|
/**
|
|
33
33
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
34
34
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -91,6 +91,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
|
91
91
|
* @public exported from `@promptbook/core`
|
|
92
92
|
*/
|
|
93
93
|
const ADMIN_GITHUB_NAME = 'hejny';
|
|
94
|
+
// <- TODO: [🐊] Pick the best claim
|
|
94
95
|
/**
|
|
95
96
|
* When the title is not provided, the default title is used
|
|
96
97
|
*
|
|
@@ -123,6 +124,7 @@ const VALUE_STRINGS = {
|
|
|
123
124
|
infinity: '(infinity; ∞)',
|
|
124
125
|
negativeInfinity: '(negative infinity; -∞)',
|
|
125
126
|
unserializable: '(unserializable value)',
|
|
127
|
+
circular: '(circular JSON)',
|
|
126
128
|
};
|
|
127
129
|
/**
|
|
128
130
|
* Small number limit
|
|
@@ -162,7 +164,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
162
164
|
*/
|
|
163
165
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
164
166
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
165
|
-
// TODO:
|
|
167
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
166
168
|
/**
|
|
167
169
|
* Where to store the temporary downloads
|
|
168
170
|
*
|
|
@@ -1070,9 +1072,60 @@ class ParseError extends Error {
|
|
|
1070
1072
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
1071
1073
|
*/
|
|
1072
1074
|
|
|
1075
|
+
/**
|
|
1076
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
1077
|
+
*
|
|
1078
|
+
* @public exported from `@promptbook/core`
|
|
1079
|
+
*/
|
|
1080
|
+
class WrappedError extends Error {
|
|
1081
|
+
constructor(whatWasThrown) {
|
|
1082
|
+
const tag = `[🤮]`;
|
|
1083
|
+
console.error(tag, whatWasThrown);
|
|
1084
|
+
super(spaceTrim(`
|
|
1085
|
+
Non-Error object was thrown
|
|
1086
|
+
|
|
1087
|
+
Note: Look for ${tag} in the console for more details
|
|
1088
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
1089
|
+
`));
|
|
1090
|
+
this.name = 'WrappedError';
|
|
1091
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
1097
|
+
*
|
|
1098
|
+
* @param whatWasThrown Any object that was thrown
|
|
1099
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
1100
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
1101
|
+
*
|
|
1102
|
+
* @private within the repository
|
|
1103
|
+
*/
|
|
1104
|
+
function assertsError(whatWasThrown) {
|
|
1105
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
1106
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
1107
|
+
const wrappedError = whatWasThrown;
|
|
1108
|
+
throw wrappedError;
|
|
1109
|
+
}
|
|
1110
|
+
// Case 2: Handle unexpected errors
|
|
1111
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
1112
|
+
const unexpectedError = whatWasThrown;
|
|
1113
|
+
throw unexpectedError;
|
|
1114
|
+
}
|
|
1115
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
1116
|
+
if (whatWasThrown instanceof Error) {
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
1120
|
+
throw new WrappedError(whatWasThrown);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1073
1123
|
/**
|
|
1074
1124
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1075
1125
|
*
|
|
1126
|
+
* @param value The string to check
|
|
1127
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
1128
|
+
*
|
|
1076
1129
|
* @public exported from `@promptbook/utils`
|
|
1077
1130
|
*/
|
|
1078
1131
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
@@ -1081,9 +1134,7 @@ function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
|
1081
1134
|
return true;
|
|
1082
1135
|
}
|
|
1083
1136
|
catch (error) {
|
|
1084
|
-
|
|
1085
|
-
throw error;
|
|
1086
|
-
}
|
|
1137
|
+
assertsError(error);
|
|
1087
1138
|
if (error.message.includes('Unexpected token')) {
|
|
1088
1139
|
return false;
|
|
1089
1140
|
}
|
|
@@ -1436,9 +1487,7 @@ function checkSerializableAsJson(options) {
|
|
|
1436
1487
|
JSON.stringify(value); // <- TODO: [0]
|
|
1437
1488
|
}
|
|
1438
1489
|
catch (error) {
|
|
1439
|
-
|
|
1440
|
-
throw error;
|
|
1441
|
-
}
|
|
1490
|
+
assertsError(error);
|
|
1442
1491
|
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
1443
1492
|
\`${name}\` is not serializable
|
|
1444
1493
|
|
|
@@ -2209,7 +2258,7 @@ class PipelineExecutionError extends Error {
|
|
|
2209
2258
|
}
|
|
2210
2259
|
}
|
|
2211
2260
|
/**
|
|
2212
|
-
* TODO:
|
|
2261
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
2213
2262
|
*/
|
|
2214
2263
|
|
|
2215
2264
|
/**
|
|
@@ -2387,6 +2436,19 @@ class NotYetImplementedError extends Error {
|
|
|
2387
2436
|
}
|
|
2388
2437
|
}
|
|
2389
2438
|
|
|
2439
|
+
/**
|
|
2440
|
+
* Error thrown when a fetch request fails
|
|
2441
|
+
*
|
|
2442
|
+
* @public exported from `@promptbook/core`
|
|
2443
|
+
*/
|
|
2444
|
+
class PromptbookFetchError extends Error {
|
|
2445
|
+
constructor(message) {
|
|
2446
|
+
super(message);
|
|
2447
|
+
this.name = 'PromptbookFetchError';
|
|
2448
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2390
2452
|
/**
|
|
2391
2453
|
* Index of all custom errors
|
|
2392
2454
|
*
|
|
@@ -2407,7 +2469,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
2407
2469
|
PipelineExecutionError,
|
|
2408
2470
|
PipelineLogicError,
|
|
2409
2471
|
PipelineUrlError,
|
|
2472
|
+
AuthenticationError,
|
|
2473
|
+
PromptbookFetchError,
|
|
2410
2474
|
UnexpectedError,
|
|
2475
|
+
WrappedError,
|
|
2411
2476
|
// TODO: [🪑]> VersionMismatchError,
|
|
2412
2477
|
};
|
|
2413
2478
|
/**
|
|
@@ -2424,7 +2489,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
|
|
|
2424
2489
|
TypeError,
|
|
2425
2490
|
URIError,
|
|
2426
2491
|
AggregateError,
|
|
2427
|
-
AuthenticationError,
|
|
2428
2492
|
/*
|
|
2429
2493
|
Note: Not widely supported
|
|
2430
2494
|
> InternalError,
|
|
@@ -2547,8 +2611,8 @@ function createTask(options) {
|
|
|
2547
2611
|
updatedAt = new Date();
|
|
2548
2612
|
errors.push(...executionResult.errors);
|
|
2549
2613
|
warnings.push(...executionResult.warnings);
|
|
2550
|
-
// <- TODO:
|
|
2551
|
-
// TODO: [🧠]
|
|
2614
|
+
// <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
|
|
2615
|
+
// TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2552
2616
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2553
2617
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2554
2618
|
assertsTaskSuccessful(executionResult);
|
|
@@ -2558,6 +2622,7 @@ function createTask(options) {
|
|
|
2558
2622
|
partialResultSubject.next(executionResult);
|
|
2559
2623
|
}
|
|
2560
2624
|
catch (error) {
|
|
2625
|
+
assertsError(error);
|
|
2561
2626
|
status = 'ERROR';
|
|
2562
2627
|
errors.push(error);
|
|
2563
2628
|
partialResultSubject.error(error);
|
|
@@ -2949,14 +3014,15 @@ class MultipleLlmExecutionTools {
|
|
|
2949
3014
|
}
|
|
2950
3015
|
}
|
|
2951
3016
|
catch (error) {
|
|
2952
|
-
|
|
3017
|
+
assertsError(error);
|
|
3018
|
+
if (error instanceof UnexpectedError) {
|
|
2953
3019
|
throw error;
|
|
2954
3020
|
}
|
|
2955
3021
|
errors.push({ llmExecutionTools, error });
|
|
2956
3022
|
}
|
|
2957
3023
|
}
|
|
2958
3024
|
if (errors.length === 1) {
|
|
2959
|
-
throw errors[0];
|
|
3025
|
+
throw errors[0].error;
|
|
2960
3026
|
}
|
|
2961
3027
|
else if (errors.length > 1) {
|
|
2962
3028
|
throw new PipelineExecutionError(
|
|
@@ -3394,17 +3460,22 @@ function mimeTypeToExtension(value) {
|
|
|
3394
3460
|
/**
|
|
3395
3461
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3396
3462
|
*
|
|
3397
|
-
* @
|
|
3463
|
+
* @public exported from `@promptbook/core`
|
|
3398
3464
|
*/
|
|
3399
|
-
const
|
|
3465
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3400
3466
|
try {
|
|
3401
|
-
return await fetch(
|
|
3467
|
+
return await fetch(urlOrRequest, init);
|
|
3402
3468
|
}
|
|
3403
3469
|
catch (error) {
|
|
3404
|
-
|
|
3405
|
-
|
|
3470
|
+
assertsError(error);
|
|
3471
|
+
let url;
|
|
3472
|
+
if (typeof urlOrRequest === 'string') {
|
|
3473
|
+
url = urlOrRequest;
|
|
3474
|
+
}
|
|
3475
|
+
else if (urlOrRequest instanceof Request) {
|
|
3476
|
+
url = urlOrRequest.url;
|
|
3406
3477
|
}
|
|
3407
|
-
throw new
|
|
3478
|
+
throw new PromptbookFetchError(spaceTrim$1((block) => `
|
|
3408
3479
|
Can not fetch "${url}"
|
|
3409
3480
|
|
|
3410
3481
|
Fetch error:
|
|
@@ -3425,7 +3496,7 @@ const scraperFetch = async (url, init) => {
|
|
|
3425
3496
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3426
3497
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3427
3498
|
var _a;
|
|
3428
|
-
const { fetch =
|
|
3499
|
+
const { fetch = promptbookFetch } = tools;
|
|
3429
3500
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3430
3501
|
let { name } = knowledgeSource;
|
|
3431
3502
|
const { rootDirname = null,
|
|
@@ -3627,9 +3698,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3627
3698
|
knowledgePreparedUnflatten[index] = pieces;
|
|
3628
3699
|
}
|
|
3629
3700
|
catch (error) {
|
|
3630
|
-
|
|
3631
|
-
throw error;
|
|
3632
|
-
}
|
|
3701
|
+
assertsError(error);
|
|
3633
3702
|
console.warn(error);
|
|
3634
3703
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3635
3704
|
}
|
|
@@ -3921,13 +3990,19 @@ function valueToString(value) {
|
|
|
3921
3990
|
return value.toISOString();
|
|
3922
3991
|
}
|
|
3923
3992
|
else {
|
|
3924
|
-
|
|
3993
|
+
try {
|
|
3994
|
+
return JSON.stringify(value);
|
|
3995
|
+
}
|
|
3996
|
+
catch (error) {
|
|
3997
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
3998
|
+
return VALUE_STRINGS.circular;
|
|
3999
|
+
}
|
|
4000
|
+
throw error;
|
|
4001
|
+
}
|
|
3925
4002
|
}
|
|
3926
4003
|
}
|
|
3927
4004
|
catch (error) {
|
|
3928
|
-
|
|
3929
|
-
throw error;
|
|
3930
|
-
}
|
|
4005
|
+
assertsError(error);
|
|
3931
4006
|
console.error(error);
|
|
3932
4007
|
return VALUE_STRINGS.unserializable;
|
|
3933
4008
|
}
|
|
@@ -3984,9 +4059,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
3984
4059
|
}
|
|
3985
4060
|
}
|
|
3986
4061
|
catch (error) {
|
|
3987
|
-
|
|
3988
|
-
throw error;
|
|
3989
|
-
}
|
|
4062
|
+
assertsError(error);
|
|
3990
4063
|
throw new ParseError(spaceTrim((block) => `
|
|
3991
4064
|
Can not extract variables from the script
|
|
3992
4065
|
${block(error.stack || error.message)}
|
|
@@ -4105,6 +4178,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
4105
4178
|
// encoding: 'utf-8',
|
|
4106
4179
|
});
|
|
4107
4180
|
|
|
4181
|
+
/**
|
|
4182
|
+
* Function to check if a string is valid CSV
|
|
4183
|
+
*
|
|
4184
|
+
* @param value The string to check
|
|
4185
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
4186
|
+
*
|
|
4187
|
+
* @public exported from `@promptbook/utils`
|
|
4188
|
+
*/
|
|
4189
|
+
function isValidCsvString(value) {
|
|
4190
|
+
try {
|
|
4191
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
4192
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
4193
|
+
return true;
|
|
4194
|
+
}
|
|
4195
|
+
return false;
|
|
4196
|
+
}
|
|
4197
|
+
catch (error) {
|
|
4198
|
+
assertsError(error);
|
|
4199
|
+
return false;
|
|
4200
|
+
}
|
|
4201
|
+
}
|
|
4202
|
+
|
|
4108
4203
|
/**
|
|
4109
4204
|
* Definition for CSV spreadsheet
|
|
4110
4205
|
*
|
|
@@ -4115,7 +4210,7 @@ const CsvFormatDefinition = {
|
|
|
4115
4210
|
formatName: 'CSV',
|
|
4116
4211
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
4117
4212
|
isValid(value, settings, schema) {
|
|
4118
|
-
return
|
|
4213
|
+
return isValidCsvString(value);
|
|
4119
4214
|
},
|
|
4120
4215
|
canBeValid(partialValue, settings, schema) {
|
|
4121
4216
|
return true;
|
|
@@ -4269,6 +4364,30 @@ const TextFormatDefinition = {
|
|
|
4269
4364
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
4270
4365
|
*/
|
|
4271
4366
|
|
|
4367
|
+
/**
|
|
4368
|
+
* Function to check if a string is valid XML
|
|
4369
|
+
*
|
|
4370
|
+
* @param value
|
|
4371
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
4372
|
+
*
|
|
4373
|
+
* @public exported from `@promptbook/utils`
|
|
4374
|
+
*/
|
|
4375
|
+
function isValidXmlString(value) {
|
|
4376
|
+
try {
|
|
4377
|
+
const parser = new DOMParser();
|
|
4378
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
4379
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
4380
|
+
if (parserError.length > 0) {
|
|
4381
|
+
return false;
|
|
4382
|
+
}
|
|
4383
|
+
return true;
|
|
4384
|
+
}
|
|
4385
|
+
catch (error) {
|
|
4386
|
+
assertsError(error);
|
|
4387
|
+
return false;
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
|
|
4272
4391
|
/**
|
|
4273
4392
|
* Definition for XML format
|
|
4274
4393
|
*
|
|
@@ -4278,7 +4397,7 @@ const XmlFormatDefinition = {
|
|
|
4278
4397
|
formatName: 'XML',
|
|
4279
4398
|
mimeType: 'application/xml',
|
|
4280
4399
|
isValid(value, settings, schema) {
|
|
4281
|
-
return
|
|
4400
|
+
return isValidXmlString(value);
|
|
4282
4401
|
},
|
|
4283
4402
|
canBeValid(partialValue, settings, schema) {
|
|
4284
4403
|
return true;
|
|
@@ -4851,9 +4970,7 @@ async function executeAttempts(options) {
|
|
|
4851
4970
|
break scripts;
|
|
4852
4971
|
}
|
|
4853
4972
|
catch (error) {
|
|
4854
|
-
|
|
4855
|
-
throw error;
|
|
4856
|
-
}
|
|
4973
|
+
assertsError(error);
|
|
4857
4974
|
if (error instanceof UnexpectedError) {
|
|
4858
4975
|
throw error;
|
|
4859
4976
|
}
|
|
@@ -4923,9 +5040,7 @@ async function executeAttempts(options) {
|
|
|
4923
5040
|
break scripts;
|
|
4924
5041
|
}
|
|
4925
5042
|
catch (error) {
|
|
4926
|
-
|
|
4927
|
-
throw error;
|
|
4928
|
-
}
|
|
5043
|
+
assertsError(error);
|
|
4929
5044
|
if (error instanceof UnexpectedError) {
|
|
4930
5045
|
throw error;
|
|
4931
5046
|
}
|
|
@@ -5546,9 +5661,7 @@ async function executePipeline(options) {
|
|
|
5546
5661
|
await Promise.all(resolving);
|
|
5547
5662
|
}
|
|
5548
5663
|
catch (error /* <- Note: [3] */) {
|
|
5549
|
-
|
|
5550
|
-
throw error;
|
|
5551
|
-
}
|
|
5664
|
+
assertsError(error);
|
|
5552
5665
|
// Note: No need to rethrow UnexpectedError
|
|
5553
5666
|
// if (error instanceof UnexpectedError) {
|
|
5554
5667
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|