@promptbook/remote-client 0.89.0-9 → 0.92.0-10
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 +180 -57
- 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 +14 -4
- package/esm/typings/src/_packages/deepseek.index.d.ts +2 -0
- package/esm/typings/src/_packages/google.index.d.ts +2 -0
- package/esm/typings/src/_packages/types.index.d.ts +18 -0
- package/esm/typings/src/_packages/utils.index.d.ts +6 -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/conversion/archive/loadArchive.d.ts +2 -2
- package/esm/typings/src/errors/0-index.d.ts +7 -4
- package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
- 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/CommonToolsOptions.d.ts +4 -0
- package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
- package/esm/typings/src/execution/createPipelineExecutor/getKnowledgeForTask.d.ts +12 -0
- package/esm/typings/src/execution/createPipelineExecutor/getReservedParametersForTask.d.ts +5 -0
- package/esm/typings/src/formats/csv/utils/csvParse.d.ts +12 -0
- 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/json/utils/jsonParse.d.ts +11 -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/filterModels.d.ts +15 -0
- package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts → $provideEnvFilename.d.ts} +2 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
- package/esm/typings/src/llm-providers/_common/register/LlmToolsMetadata.d.ts +43 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/llm-providers/deepseek/deepseek-models.d.ts +23 -0
- package/esm/typings/src/llm-providers/google/google-models.d.ts +23 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +4 -0
- package/esm/typings/src/personas/preparePersona.d.ts +1 -1
- package/esm/typings/src/pipeline/PipelineJson/PersonaJson.d.ts +4 -2
- package/esm/typings/src/remote-server/openapi-types.d.ts +626 -0
- package/esm/typings/src/remote-server/openapi.d.ts +581 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/Identification.d.ts +7 -1
- 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/startRemoteServer.d.ts +1 -2
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
- 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 +7 -3
- package/umd/index.umd.js +180 -57
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
package/README.md
CHANGED
|
@@ -244,6 +244,10 @@ But unlike programming languages, it is designed to be understandable by non-pro
|
|
|
244
244
|
|
|
245
245
|
|
|
246
246
|
|
|
247
|
+
## 🔒 Security
|
|
248
|
+
|
|
249
|
+
For information on reporting security vulnerabilities, see our [Security Policy](./SECURITY.md).
|
|
250
|
+
|
|
247
251
|
## 📦 Packages _(for developers)_
|
|
248
252
|
|
|
249
253
|
This library is divided into several packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -300,7 +304,7 @@ The following glossary is used to clarify certain concepts:
|
|
|
300
304
|
### General LLM / AI terms
|
|
301
305
|
|
|
302
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.
|
|
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.
|
|
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)
|
|
304
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.
|
|
305
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.
|
|
306
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.
|
|
@@ -308,10 +312,6 @@ The following glossary is used to clarify certain concepts:
|
|
|
308
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.
|
|
309
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.
|
|
310
314
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
315
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
316
316
|
|
|
317
317
|
|
|
@@ -425,6 +425,8 @@ See [TODO.md](./TODO.md)
|
|
|
425
425
|
|
|
426
426
|
## 🖋️ Contributing
|
|
427
427
|
|
|
428
|
-
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
|
|
429
431
|
|
|
430
|
-
|
|
432
|
+
If you need help or have questions, please check our [Support Resources](./SUPPORT.md).
|
package/esm/index.es.js
CHANGED
|
@@ -20,7 +20,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
20
20
|
* @generated
|
|
21
21
|
* @see https://github.com/webgptorg/promptbook
|
|
22
22
|
*/
|
|
23
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
23
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-10';
|
|
24
24
|
/**
|
|
25
25
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
26
26
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -238,7 +238,7 @@ class PipelineExecutionError extends Error {
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
|
-
* TODO:
|
|
241
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
242
242
|
*/
|
|
243
243
|
|
|
244
244
|
/**
|
|
@@ -320,6 +320,7 @@ const ADMIN_EMAIL = 'pavol@ptbk.io';
|
|
|
320
320
|
* @public exported from `@promptbook/core`
|
|
321
321
|
*/
|
|
322
322
|
const ADMIN_GITHUB_NAME = 'hejny';
|
|
323
|
+
// <- TODO: [🐊] Pick the best claim
|
|
323
324
|
/**
|
|
324
325
|
* When the title is not provided, the default title is used
|
|
325
326
|
*
|
|
@@ -443,6 +444,26 @@ class UnexpectedError extends Error {
|
|
|
443
444
|
}
|
|
444
445
|
}
|
|
445
446
|
|
|
447
|
+
/**
|
|
448
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
449
|
+
*
|
|
450
|
+
* @public exported from `@promptbook/core`
|
|
451
|
+
*/
|
|
452
|
+
class WrappedError extends Error {
|
|
453
|
+
constructor(whatWasThrown) {
|
|
454
|
+
const tag = `[🤮]`;
|
|
455
|
+
console.error(tag, whatWasThrown);
|
|
456
|
+
super(spaceTrim(`
|
|
457
|
+
Non-Error object was thrown
|
|
458
|
+
|
|
459
|
+
Note: Look for ${tag} in the console for more details
|
|
460
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
461
|
+
`));
|
|
462
|
+
this.name = 'WrappedError';
|
|
463
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
446
467
|
/**
|
|
447
468
|
* Index of all custom errors
|
|
448
469
|
*
|
|
@@ -463,7 +484,10 @@ const PROMPTBOOK_ERRORS = {
|
|
|
463
484
|
PipelineExecutionError,
|
|
464
485
|
PipelineLogicError,
|
|
465
486
|
PipelineUrlError,
|
|
487
|
+
AuthenticationError,
|
|
488
|
+
PromptbookFetchError,
|
|
466
489
|
UnexpectedError,
|
|
490
|
+
WrappedError,
|
|
467
491
|
// TODO: [🪑]> VersionMismatchError,
|
|
468
492
|
};
|
|
469
493
|
/**
|
|
@@ -480,8 +504,6 @@ const COMMON_JAVASCRIPT_ERRORS = {
|
|
|
480
504
|
TypeError,
|
|
481
505
|
URIError,
|
|
482
506
|
AggregateError,
|
|
483
|
-
AuthenticationError,
|
|
484
|
-
PromptbookFetchError,
|
|
485
507
|
/*
|
|
486
508
|
Note: Not widely supported
|
|
487
509
|
> InternalError,
|
|
@@ -530,6 +552,35 @@ function deserializeError(error) {
|
|
|
530
552
|
return deserializedError;
|
|
531
553
|
}
|
|
532
554
|
|
|
555
|
+
/**
|
|
556
|
+
* Tests if given string is valid URL.
|
|
557
|
+
*
|
|
558
|
+
* Note: Dataurl are considered perfectly valid.
|
|
559
|
+
* Note: There are two simmilar functions:
|
|
560
|
+
* - `isValidUrl` which tests any URL
|
|
561
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
562
|
+
*
|
|
563
|
+
* @public exported from `@promptbook/utils`
|
|
564
|
+
*/
|
|
565
|
+
function isValidUrl(url) {
|
|
566
|
+
if (typeof url !== 'string') {
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
try {
|
|
570
|
+
if (url.startsWith('blob:')) {
|
|
571
|
+
url = url.replace(/^blob:/, '');
|
|
572
|
+
}
|
|
573
|
+
const urlObject = new URL(url /* because fail is handled */);
|
|
574
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
return true;
|
|
578
|
+
}
|
|
579
|
+
catch (error) {
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
533
584
|
/**
|
|
534
585
|
* Creates a connection to the remote proxy server.
|
|
535
586
|
*
|
|
@@ -539,17 +590,31 @@ function deserializeError(error) {
|
|
|
539
590
|
*/
|
|
540
591
|
async function createRemoteClient(options) {
|
|
541
592
|
const { remoteServerUrl } = options;
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
593
|
+
if (!isValidUrl(remoteServerUrl)) {
|
|
594
|
+
throw new Error(`Invalid \`remoteServerUrl\`: "${remoteServerUrl}"`);
|
|
595
|
+
}
|
|
596
|
+
const remoteServerUrlParsed = new URL(remoteServerUrl);
|
|
597
|
+
if (remoteServerUrlParsed.pathname !== '/' && remoteServerUrlParsed.pathname !== '') {
|
|
598
|
+
remoteServerUrlParsed.pathname = '/';
|
|
599
|
+
throw new Error(spaceTrim$1((block) => `
|
|
600
|
+
Remote server requires root url \`/\`
|
|
601
|
+
|
|
602
|
+
You have provided \`remoteServerUrl\`:
|
|
603
|
+
${block(remoteServerUrl)}
|
|
604
|
+
|
|
605
|
+
But something like this is expected:
|
|
606
|
+
${block(remoteServerUrlParsed.href)}
|
|
607
|
+
|
|
608
|
+
Note: If you need to run multiple services on the same server, use 3rd or 4th degree subdomain
|
|
609
|
+
|
|
610
|
+
`));
|
|
545
611
|
}
|
|
546
|
-
path = `${path}/socket.io`;
|
|
547
612
|
return new Promise((resolve, reject) => {
|
|
548
613
|
const socket = io(remoteServerUrl, {
|
|
549
614
|
retries: CONNECTION_RETRIES_LIMIT,
|
|
550
615
|
timeout: CONNECTION_TIMEOUT_MS,
|
|
551
|
-
path,
|
|
552
|
-
transports: [
|
|
616
|
+
path: '/socket.io',
|
|
617
|
+
transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
|
|
553
618
|
});
|
|
554
619
|
// console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
|
|
555
620
|
socket.on('connect', () => {
|
|
@@ -683,35 +748,6 @@ function isValidFilePath(filename) {
|
|
|
683
748
|
* TODO: [🍏] Implement for MacOs
|
|
684
749
|
*/
|
|
685
750
|
|
|
686
|
-
/**
|
|
687
|
-
* Tests if given string is valid URL.
|
|
688
|
-
*
|
|
689
|
-
* Note: Dataurl are considered perfectly valid.
|
|
690
|
-
* Note: There are two simmilar functions:
|
|
691
|
-
* - `isValidUrl` which tests any URL
|
|
692
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
693
|
-
*
|
|
694
|
-
* @public exported from `@promptbook/utils`
|
|
695
|
-
*/
|
|
696
|
-
function isValidUrl(url) {
|
|
697
|
-
if (typeof url !== 'string') {
|
|
698
|
-
return false;
|
|
699
|
-
}
|
|
700
|
-
try {
|
|
701
|
-
if (url.startsWith('blob:')) {
|
|
702
|
-
url = url.replace(/^blob:/, '');
|
|
703
|
-
}
|
|
704
|
-
const urlObject = new URL(url /* because fail is handled */);
|
|
705
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
706
|
-
return false;
|
|
707
|
-
}
|
|
708
|
-
return true;
|
|
709
|
-
}
|
|
710
|
-
catch (error) {
|
|
711
|
-
return false;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
|
|
715
751
|
const defaultDiacriticsRemovalMap = [
|
|
716
752
|
{
|
|
717
753
|
base: 'A',
|
|
@@ -1539,6 +1575,34 @@ const bookVersionCommandParser = {
|
|
|
1539
1575
|
},
|
|
1540
1576
|
};
|
|
1541
1577
|
|
|
1578
|
+
/**
|
|
1579
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
1580
|
+
*
|
|
1581
|
+
* @param whatWasThrown Any object that was thrown
|
|
1582
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
1583
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
1584
|
+
*
|
|
1585
|
+
* @private within the repository
|
|
1586
|
+
*/
|
|
1587
|
+
function assertsError(whatWasThrown) {
|
|
1588
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
1589
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
1590
|
+
const wrappedError = whatWasThrown;
|
|
1591
|
+
throw wrappedError;
|
|
1592
|
+
}
|
|
1593
|
+
// Case 2: Handle unexpected errors
|
|
1594
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
1595
|
+
const unexpectedError = whatWasThrown;
|
|
1596
|
+
throw unexpectedError;
|
|
1597
|
+
}
|
|
1598
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
1599
|
+
if (whatWasThrown instanceof Error) {
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
1603
|
+
throw new WrappedError(whatWasThrown);
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1542
1606
|
/**
|
|
1543
1607
|
* Units of text measurement
|
|
1544
1608
|
*
|
|
@@ -1619,6 +1683,8 @@ function parseNumber(value) {
|
|
|
1619
1683
|
*/
|
|
1620
1684
|
|
|
1621
1685
|
/**
|
|
1686
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
1687
|
+
import { assertsError } from '../../errors/assertsError';
|
|
1622
1688
|
* Parses the expect command
|
|
1623
1689
|
*
|
|
1624
1690
|
* @see `documentationUrl` for more details
|
|
@@ -1710,9 +1776,7 @@ const expectCommandParser = {
|
|
|
1710
1776
|
};
|
|
1711
1777
|
}
|
|
1712
1778
|
catch (error) {
|
|
1713
|
-
|
|
1714
|
-
throw error;
|
|
1715
|
-
}
|
|
1779
|
+
assertsError(error);
|
|
1716
1780
|
throw new ParseError(spaceTrim$1((block) => `
|
|
1717
1781
|
Invalid FORMAT command
|
|
1718
1782
|
${block(error.message)}:
|
|
@@ -1770,6 +1834,46 @@ const MANDATORY_CSV_SETTINGS = Object.freeze({
|
|
|
1770
1834
|
// encoding: 'utf-8',
|
|
1771
1835
|
});
|
|
1772
1836
|
|
|
1837
|
+
/**
|
|
1838
|
+
* Function to check if a string is valid CSV
|
|
1839
|
+
*
|
|
1840
|
+
* @param value The string to check
|
|
1841
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
1842
|
+
*
|
|
1843
|
+
* @public exported from `@promptbook/utils`
|
|
1844
|
+
*/
|
|
1845
|
+
function isValidCsvString(value) {
|
|
1846
|
+
try {
|
|
1847
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
1848
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
1849
|
+
return true;
|
|
1850
|
+
}
|
|
1851
|
+
return false;
|
|
1852
|
+
}
|
|
1853
|
+
catch (error) {
|
|
1854
|
+
assertsError(error);
|
|
1855
|
+
return false;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
/**
|
|
1860
|
+
* Converts a CSV string into an object
|
|
1861
|
+
*
|
|
1862
|
+
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
1863
|
+
*
|
|
1864
|
+
* @private - for now until `@promptbook/csv` is released
|
|
1865
|
+
*/
|
|
1866
|
+
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
1867
|
+
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
1868
|
+
// Note: Autoheal invalid '\n' characters
|
|
1869
|
+
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
1870
|
+
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
1871
|
+
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
1872
|
+
}
|
|
1873
|
+
const csv = parse(value, settings);
|
|
1874
|
+
return csv;
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1773
1877
|
/**
|
|
1774
1878
|
* Definition for CSV spreadsheet
|
|
1775
1879
|
*
|
|
@@ -1780,7 +1884,7 @@ const CsvFormatDefinition = {
|
|
|
1780
1884
|
formatName: 'CSV',
|
|
1781
1885
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
1782
1886
|
isValid(value, settings, schema) {
|
|
1783
|
-
return
|
|
1887
|
+
return isValidCsvString(value);
|
|
1784
1888
|
},
|
|
1785
1889
|
canBeValid(partialValue, settings, schema) {
|
|
1786
1890
|
return true;
|
|
@@ -1792,8 +1896,7 @@ const CsvFormatDefinition = {
|
|
|
1792
1896
|
{
|
|
1793
1897
|
subvalueName: 'ROW',
|
|
1794
1898
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
1795
|
-
|
|
1796
|
-
const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
1899
|
+
const csv = csvParse(value, settings);
|
|
1797
1900
|
if (csv.errors.length !== 0) {
|
|
1798
1901
|
throw new CsvFormatError(spaceTrim$1((block) => `
|
|
1799
1902
|
CSV parsing error
|
|
@@ -1823,8 +1926,7 @@ const CsvFormatDefinition = {
|
|
|
1823
1926
|
{
|
|
1824
1927
|
subvalueName: 'CELL',
|
|
1825
1928
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
1826
|
-
|
|
1827
|
-
const csv = parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
1929
|
+
const csv = csvParse(value, settings);
|
|
1828
1930
|
if (csv.errors.length !== 0) {
|
|
1829
1931
|
throw new CsvFormatError(spaceTrim$1((block) => `
|
|
1830
1932
|
CSV parsing error
|
|
@@ -1861,6 +1963,9 @@ const CsvFormatDefinition = {
|
|
|
1861
1963
|
/**
|
|
1862
1964
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1863
1965
|
*
|
|
1966
|
+
* @param value The string to check
|
|
1967
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
1968
|
+
*
|
|
1864
1969
|
* @public exported from `@promptbook/utils`
|
|
1865
1970
|
*/
|
|
1866
1971
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
@@ -1869,9 +1974,7 @@ function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
|
1869
1974
|
return true;
|
|
1870
1975
|
}
|
|
1871
1976
|
catch (error) {
|
|
1872
|
-
|
|
1873
|
-
throw error;
|
|
1874
|
-
}
|
|
1977
|
+
assertsError(error);
|
|
1875
1978
|
if (error.message.includes('Unexpected token')) {
|
|
1876
1979
|
return false;
|
|
1877
1980
|
}
|
|
@@ -1955,6 +2058,30 @@ const TextFormatDefinition = {
|
|
|
1955
2058
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
1956
2059
|
*/
|
|
1957
2060
|
|
|
2061
|
+
/**
|
|
2062
|
+
* Function to check if a string is valid XML
|
|
2063
|
+
*
|
|
2064
|
+
* @param value
|
|
2065
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
2066
|
+
*
|
|
2067
|
+
* @public exported from `@promptbook/utils`
|
|
2068
|
+
*/
|
|
2069
|
+
function isValidXmlString(value) {
|
|
2070
|
+
try {
|
|
2071
|
+
const parser = new DOMParser();
|
|
2072
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
2073
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
2074
|
+
if (parserError.length > 0) {
|
|
2075
|
+
return false;
|
|
2076
|
+
}
|
|
2077
|
+
return true;
|
|
2078
|
+
}
|
|
2079
|
+
catch (error) {
|
|
2080
|
+
assertsError(error);
|
|
2081
|
+
return false;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
|
|
1958
2085
|
/**
|
|
1959
2086
|
* Definition for XML format
|
|
1960
2087
|
*
|
|
@@ -1964,7 +2091,7 @@ const XmlFormatDefinition = {
|
|
|
1964
2091
|
formatName: 'XML',
|
|
1965
2092
|
mimeType: 'application/xml',
|
|
1966
2093
|
isValid(value, settings, schema) {
|
|
1967
|
-
return
|
|
2094
|
+
return isValidXmlString(value);
|
|
1968
2095
|
},
|
|
1969
2096
|
canBeValid(partialValue, settings, schema) {
|
|
1970
2097
|
return true;
|
|
@@ -2189,9 +2316,7 @@ function checkSerializableAsJson(options) {
|
|
|
2189
2316
|
JSON.stringify(value); // <- TODO: [0]
|
|
2190
2317
|
}
|
|
2191
2318
|
catch (error) {
|
|
2192
|
-
|
|
2193
|
-
throw error;
|
|
2194
|
-
}
|
|
2319
|
+
assertsError(error);
|
|
2195
2320
|
throw new UnexpectedError(spaceTrim$1((block) => `
|
|
2196
2321
|
\`${name}\` is not serializable
|
|
2197
2322
|
|
|
@@ -4846,9 +4971,7 @@ function extractVariablesFromJavascript(script) {
|
|
|
4846
4971
|
}
|
|
4847
4972
|
}
|
|
4848
4973
|
catch (error) {
|
|
4849
|
-
|
|
4850
|
-
throw error;
|
|
4851
|
-
}
|
|
4974
|
+
assertsError(error);
|
|
4852
4975
|
throw new ParseError(spaceTrim((block) => `
|
|
4853
4976
|
Can not extract variables from the script
|
|
4854
4977
|
${block(error.stack || error.message)}
|