@promptbook/markitdown 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 +9 -5
- 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/markitdown`
|
|
31
27
|
|
|
32
28
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -244,6 +240,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
|
|
|
244
240
|
|
|
245
241
|
|
|
246
242
|
|
|
243
|
+
## 🔒 Security
|
|
244
|
+
|
|
245
|
+
For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
|
|
246
|
+
|
|
247
247
|
## 📦 Packages _(for developers)_
|
|
248
248
|
|
|
249
249
|
This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -300,7 +300,7 @@ The following glossary is used to clarify certain concepts:
|
|
|
300
300
|
### General LLM / AI terms
|
|
301
301
|
|
|
302
302
|
- **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.
|
|
303
|
-
- **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.
|
|
303
|
+
- [**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)
|
|
304
304
|
- **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.
|
|
305
305
|
- **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.
|
|
306
306
|
- **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.
|
|
@@ -308,10 +308,6 @@ The following glossary is used to clarify certain concepts:
|
|
|
308
308
|
- **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.
|
|
309
309
|
- **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.
|
|
310
310
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
311
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
316
312
|
|
|
317
313
|
|
|
@@ -425,6 +421,8 @@ See [TODO.md](./TODO.md)
|
|
|
425
421
|
|
|
426
422
|
## 🖋️ Contributing
|
|
427
423
|
|
|
428
|
-
We are open to pull requests, feedback, and suggestions.
|
|
424
|
+
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).
|
|
425
|
+
|
|
426
|
+
## 📞 Support
|
|
429
427
|
|
|
430
|
-
|
|
428
|
+
If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
|
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.89.0
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -89,6 +89,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
|
89
89
|
* @public exported from `@promptbook/core`
|
|
90
90
|
*/
|
|
91
91
|
const ADMIN_GITHUB_NAME = 'hejny';
|
|
92
|
+
// <- TODO: [🐊] Pick the best claim
|
|
92
93
|
/**
|
|
93
94
|
* When the title is not provided, the default title is used
|
|
94
95
|
*
|
|
@@ -121,6 +122,7 @@ const VALUE_STRINGS = {
|
|
|
121
122
|
infinity: '(infinity; ∞)',
|
|
122
123
|
negativeInfinity: '(negative infinity; -∞)',
|
|
123
124
|
unserializable: '(unserializable value)',
|
|
125
|
+
circular: '(circular JSON)',
|
|
124
126
|
};
|
|
125
127
|
/**
|
|
126
128
|
* Small number limit
|
|
@@ -160,7 +162,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
160
162
|
*/
|
|
161
163
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
162
164
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
163
|
-
// TODO:
|
|
165
|
+
// TODO: Just `.promptbook` in config, hardcode subfolders like `download-cache` or `execution-cache`
|
|
164
166
|
/**
|
|
165
167
|
* Where to store the temporary downloads
|
|
166
168
|
*
|
|
@@ -878,9 +880,60 @@ class ParseError extends Error {
|
|
|
878
880
|
* TODO: Maybe split `ParseError` and `ApplyError`
|
|
879
881
|
*/
|
|
880
882
|
|
|
883
|
+
/**
|
|
884
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
885
|
+
*
|
|
886
|
+
* @public exported from `@promptbook/core`
|
|
887
|
+
*/
|
|
888
|
+
class WrappedError extends Error {
|
|
889
|
+
constructor(whatWasThrown) {
|
|
890
|
+
const tag = `[🤮]`;
|
|
891
|
+
console.error(tag, whatWasThrown);
|
|
892
|
+
super(spaceTrim$1(`
|
|
893
|
+
Non-Error object was thrown
|
|
894
|
+
|
|
895
|
+
Note: Look for ${tag} in the console for more details
|
|
896
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
897
|
+
`));
|
|
898
|
+
this.name = 'WrappedError';
|
|
899
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
905
|
+
*
|
|
906
|
+
* @param whatWasThrown Any object that was thrown
|
|
907
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
908
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
909
|
+
*
|
|
910
|
+
* @private within the repository
|
|
911
|
+
*/
|
|
912
|
+
function assertsError(whatWasThrown) {
|
|
913
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
914
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
915
|
+
const wrappedError = whatWasThrown;
|
|
916
|
+
throw wrappedError;
|
|
917
|
+
}
|
|
918
|
+
// Case 2: Handle unexpected errors
|
|
919
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
920
|
+
const unexpectedError = whatWasThrown;
|
|
921
|
+
throw unexpectedError;
|
|
922
|
+
}
|
|
923
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
924
|
+
if (whatWasThrown instanceof Error) {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
928
|
+
throw new WrappedError(whatWasThrown);
|
|
929
|
+
}
|
|
930
|
+
|
|
881
931
|
/**
|
|
882
932
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
883
933
|
*
|
|
934
|
+
* @param value The string to check
|
|
935
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
936
|
+
*
|
|
884
937
|
* @public exported from `@promptbook/utils`
|
|
885
938
|
*/
|
|
886
939
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
@@ -889,9 +942,7 @@ function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
|
889
942
|
return true;
|
|
890
943
|
}
|
|
891
944
|
catch (error) {
|
|
892
|
-
|
|
893
|
-
throw error;
|
|
894
|
-
}
|
|
945
|
+
assertsError(error);
|
|
895
946
|
if (error.message.includes('Unexpected token')) {
|
|
896
947
|
return false;
|
|
897
948
|
}
|
|
@@ -1244,9 +1295,7 @@ function checkSerializableAsJson(options) {
|
|
|
1244
1295
|
JSON.stringify(value); // <- TODO: [0]
|
|
1245
1296
|
}
|
|
1246
1297
|
catch (error) {
|
|
1247
|
-
|
|
1248
|
-
throw error;
|
|
1249
|
-
}
|
|
1298
|
+
assertsError(error);
|
|
1250
1299
|
throw new UnexpectedError(spaceTrim((block) => `
|
|
1251
1300
|
\`${name}\` is not serializable
|
|
1252
1301
|
|
|
@@ -2035,7 +2084,7 @@ class PipelineExecutionError extends Error {
|
|
|
2035
2084
|
}
|
|
2036
2085
|
}
|
|
2037
2086
|
/**
|
|
2038
|
-
* TODO:
|
|
2087
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
2039
2088
|
*/
|
|
2040
2089
|
|
|
2041
2090
|
/**
|
|
@@ -2213,6 +2262,19 @@ class NotYetImplementedError extends Error {
|
|
|
2213
2262
|
}
|
|
2214
2263
|
}
|
|
2215
2264
|
|
|
2265
|
+
/**
|
|
2266
|
+
* Error thrown when a fetch request fails
|
|
2267
|
+
*
|
|
2268
|
+
* @public exported from `@promptbook/core`
|
|
2269
|
+
*/
|
|
2270
|
+
class PromptbookFetchError extends Error {
|
|
2271
|
+
constructor(message) {
|
|
2272
|
+
super(message);
|
|
2273
|
+
this.name = 'PromptbookFetchError';
|
|
2274
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2216
2278
|
/**
|
|
2217
2279
|
* Index of all custom errors
|
|
2218
2280
|
*
|
|
@@ -2233,7 +2295,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
2233
2295
|
PipelineExecutionError,
|
|
2234
2296
|
PipelineLogicError,
|
|
2235
2297
|
PipelineUrlError,
|
|
2298
|
+
AuthenticationError,
|
|
2299
|
+
PromptbookFetchError,
|
|
2236
2300
|
UnexpectedError,
|
|
2301
|
+
WrappedError,
|
|
2237
2302
|
// TODO: [🪑]> VersionMismatchError,
|
|
2238
2303
|
};
|
|
2239
2304
|
/**
|
|
@@ -2250,7 +2315,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
|
|
|
2250
2315
|
TypeError,
|
|
2251
2316
|
URIError,
|
|
2252
2317
|
AggregateError,
|
|
2253
|
-
AuthenticationError,
|
|
2254
2318
|
/*
|
|
2255
2319
|
Note: Not widely supported
|
|
2256
2320
|
> InternalError,
|
|
@@ -2373,8 +2437,8 @@ function createTask(options) {
|
|
|
2373
2437
|
updatedAt = new Date();
|
|
2374
2438
|
errors.push(...executionResult.errors);
|
|
2375
2439
|
warnings.push(...executionResult.warnings);
|
|
2376
|
-
// <- TODO:
|
|
2377
|
-
// TODO: [🧠]
|
|
2440
|
+
// <- TODO: [🌂] Only unique errors and warnings should be added (or filtered)
|
|
2441
|
+
// TODO: [🧠] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
|
|
2378
2442
|
// Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
|
|
2379
2443
|
// And delete `ExecutionTask.currentValue.preparedPipeline`
|
|
2380
2444
|
assertsTaskSuccessful(executionResult);
|
|
@@ -2384,6 +2448,7 @@ function createTask(options) {
|
|
|
2384
2448
|
partialResultSubject.next(executionResult);
|
|
2385
2449
|
}
|
|
2386
2450
|
catch (error) {
|
|
2451
|
+
assertsError(error);
|
|
2387
2452
|
status = 'ERROR';
|
|
2388
2453
|
errors.push(error);
|
|
2389
2454
|
partialResultSubject.error(error);
|
|
@@ -2775,14 +2840,15 @@ class MultipleLlmExecutionTools {
|
|
|
2775
2840
|
}
|
|
2776
2841
|
}
|
|
2777
2842
|
catch (error) {
|
|
2778
|
-
|
|
2843
|
+
assertsError(error);
|
|
2844
|
+
if (error instanceof UnexpectedError) {
|
|
2779
2845
|
throw error;
|
|
2780
2846
|
}
|
|
2781
2847
|
errors.push({ llmExecutionTools, error });
|
|
2782
2848
|
}
|
|
2783
2849
|
}
|
|
2784
2850
|
if (errors.length === 1) {
|
|
2785
|
-
throw errors[0];
|
|
2851
|
+
throw errors[0].error;
|
|
2786
2852
|
}
|
|
2787
2853
|
else if (errors.length > 1) {
|
|
2788
2854
|
throw new PipelineExecutionError(
|
|
@@ -3230,17 +3296,22 @@ function mimeTypeToExtension(value) {
|
|
|
3230
3296
|
/**
|
|
3231
3297
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3232
3298
|
*
|
|
3233
|
-
* @
|
|
3299
|
+
* @public exported from `@promptbook/core`
|
|
3234
3300
|
*/
|
|
3235
|
-
const
|
|
3301
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3236
3302
|
try {
|
|
3237
|
-
return await fetch(
|
|
3303
|
+
return await fetch(urlOrRequest, init);
|
|
3238
3304
|
}
|
|
3239
3305
|
catch (error) {
|
|
3240
|
-
|
|
3241
|
-
|
|
3306
|
+
assertsError(error);
|
|
3307
|
+
let url;
|
|
3308
|
+
if (typeof urlOrRequest === 'string') {
|
|
3309
|
+
url = urlOrRequest;
|
|
3310
|
+
}
|
|
3311
|
+
else if (urlOrRequest instanceof Request) {
|
|
3312
|
+
url = urlOrRequest.url;
|
|
3242
3313
|
}
|
|
3243
|
-
throw new
|
|
3314
|
+
throw new PromptbookFetchError(spaceTrim((block) => `
|
|
3244
3315
|
Can not fetch "${url}"
|
|
3245
3316
|
|
|
3246
3317
|
Fetch error:
|
|
@@ -3261,7 +3332,7 @@ const scraperFetch = async (url, init) => {
|
|
|
3261
3332
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3262
3333
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3263
3334
|
var _a;
|
|
3264
|
-
const { fetch =
|
|
3335
|
+
const { fetch = promptbookFetch } = tools;
|
|
3265
3336
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3266
3337
|
let { name } = knowledgeSource;
|
|
3267
3338
|
const { rootDirname = null,
|
|
@@ -3463,9 +3534,7 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3463
3534
|
knowledgePreparedUnflatten[index] = pieces;
|
|
3464
3535
|
}
|
|
3465
3536
|
catch (error) {
|
|
3466
|
-
|
|
3467
|
-
throw error;
|
|
3468
|
-
}
|
|
3537
|
+
assertsError(error);
|
|
3469
3538
|
console.warn(error);
|
|
3470
3539
|
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3471
3540
|
}
|
|
@@ -3757,13 +3826,19 @@ function valueToString(value) {
|
|
|
3757
3826
|
return value.toISOString();
|
|
3758
3827
|
}
|
|
3759
3828
|
else {
|
|
3760
|
-
|
|
3829
|
+
try {
|
|
3830
|
+
return JSON.stringify(value);
|
|
3831
|
+
}
|
|
3832
|
+
catch (error) {
|
|
3833
|
+
if (error instanceof TypeError && error.message.includes('circular structure')) {
|
|
3834
|
+
return VALUE_STRINGS.circular;
|
|
3835
|
+
}
|
|
3836
|
+
throw error;
|
|
3837
|
+
}
|
|
3761
3838
|
}
|
|
3762
3839
|
}
|
|
3763
3840
|
catch (error) {
|
|
3764
|
-
|
|
3765
|
-
throw error;
|
|
3766
|
-
}
|
|
3841
|
+
assertsError(error);
|
|
3767
3842
|
console.error(error);
|
|
3768
3843
|
return VALUE_STRINGS.unserializable;
|
|
3769
3844
|
}
|
|
@@ -3820,9 +3895,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
3820
3895
|
}
|
|
3821
3896
|
}
|
|
3822
3897
|
catch (error) {
|
|
3823
|
-
|
|
3824
|
-
throw error;
|
|
3825
|
-
}
|
|
3898
|
+
assertsError(error);
|
|
3826
3899
|
throw new ParseError(spaceTrim$1((block) => `
|
|
3827
3900
|
Can not extract variables from the script
|
|
3828
3901
|
${block(error.stack || error.message)}
|
|
@@ -3941,6 +4014,28 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
3941
4014
|
// encoding: 'utf-8',
|
|
3942
4015
|
});
|
|
3943
4016
|
|
|
4017
|
+
/**
|
|
4018
|
+
* Function to check if a string is valid CSV
|
|
4019
|
+
*
|
|
4020
|
+
* @param value The string to check
|
|
4021
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
4022
|
+
*
|
|
4023
|
+
* @public exported from `@promptbook/utils`
|
|
4024
|
+
*/
|
|
4025
|
+
function isValidCsvString(value) {
|
|
4026
|
+
try {
|
|
4027
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
4028
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
4029
|
+
return true;
|
|
4030
|
+
}
|
|
4031
|
+
return false;
|
|
4032
|
+
}
|
|
4033
|
+
catch (error) {
|
|
4034
|
+
assertsError(error);
|
|
4035
|
+
return false;
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
|
|
3944
4039
|
/**
|
|
3945
4040
|
* Definition for CSV spreadsheet
|
|
3946
4041
|
*
|
|
@@ -3951,7 +4046,7 @@ const CsvFormatDefinition = {
|
|
|
3951
4046
|
formatName: 'CSV',
|
|
3952
4047
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
3953
4048
|
isValid(value, settings, schema) {
|
|
3954
|
-
return
|
|
4049
|
+
return isValidCsvString(value);
|
|
3955
4050
|
},
|
|
3956
4051
|
canBeValid(partialValue, settings, schema) {
|
|
3957
4052
|
return true;
|
|
@@ -4105,6 +4200,30 @@ const TextFormatDefinition = {
|
|
|
4105
4200
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
4106
4201
|
*/
|
|
4107
4202
|
|
|
4203
|
+
/**
|
|
4204
|
+
* Function to check if a string is valid XML
|
|
4205
|
+
*
|
|
4206
|
+
* @param value
|
|
4207
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
4208
|
+
*
|
|
4209
|
+
* @public exported from `@promptbook/utils`
|
|
4210
|
+
*/
|
|
4211
|
+
function isValidXmlString(value) {
|
|
4212
|
+
try {
|
|
4213
|
+
const parser = new DOMParser();
|
|
4214
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
4215
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
4216
|
+
if (parserError.length > 0) {
|
|
4217
|
+
return false;
|
|
4218
|
+
}
|
|
4219
|
+
return true;
|
|
4220
|
+
}
|
|
4221
|
+
catch (error) {
|
|
4222
|
+
assertsError(error);
|
|
4223
|
+
return false;
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
|
|
4108
4227
|
/**
|
|
4109
4228
|
* Definition for XML format
|
|
4110
4229
|
*
|
|
@@ -4114,7 +4233,7 @@ const XmlFormatDefinition = {
|
|
|
4114
4233
|
formatName: 'XML',
|
|
4115
4234
|
mimeType: 'application/xml',
|
|
4116
4235
|
isValid(value, settings, schema) {
|
|
4117
|
-
return
|
|
4236
|
+
return isValidXmlString(value);
|
|
4118
4237
|
},
|
|
4119
4238
|
canBeValid(partialValue, settings, schema) {
|
|
4120
4239
|
return true;
|
|
@@ -4687,9 +4806,7 @@ async function executeAttempts(options) {
|
|
|
4687
4806
|
break scripts;
|
|
4688
4807
|
}
|
|
4689
4808
|
catch (error) {
|
|
4690
|
-
|
|
4691
|
-
throw error;
|
|
4692
|
-
}
|
|
4809
|
+
assertsError(error);
|
|
4693
4810
|
if (error instanceof UnexpectedError) {
|
|
4694
4811
|
throw error;
|
|
4695
4812
|
}
|
|
@@ -4759,9 +4876,7 @@ async function executeAttempts(options) {
|
|
|
4759
4876
|
break scripts;
|
|
4760
4877
|
}
|
|
4761
4878
|
catch (error) {
|
|
4762
|
-
|
|
4763
|
-
throw error;
|
|
4764
|
-
}
|
|
4879
|
+
assertsError(error);
|
|
4765
4880
|
if (error instanceof UnexpectedError) {
|
|
4766
4881
|
throw error;
|
|
4767
4882
|
}
|
|
@@ -5382,9 +5497,7 @@ async function executePipeline(options) {
|
|
|
5382
5497
|
await Promise.all(resolving);
|
|
5383
5498
|
}
|
|
5384
5499
|
catch (error /* <- Note: [3] */) {
|
|
5385
|
-
|
|
5386
|
-
throw error;
|
|
5387
|
-
}
|
|
5500
|
+
assertsError(error);
|
|
5388
5501
|
// Note: No need to rethrow UnexpectedError
|
|
5389
5502
|
// if (error instanceof UnexpectedError) {
|
|
5390
5503
|
// Note: Count usage, [🧠] Maybe put to separate function executionReportJsonToUsage + DRY [🤹♂️]
|