@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
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PromptbookStorage } from '../_common/PromptbookStorage';
|
|
2
|
+
/**
|
|
3
|
+
* Stores data in .env variables
|
|
4
|
+
*
|
|
5
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file and also writes to `process.env`
|
|
6
|
+
*
|
|
7
|
+
* @private within the repository - for CLI utils
|
|
8
|
+
*/
|
|
9
|
+
export declare class $EnvStorage<TItem> implements PromptbookStorage<TItem> {
|
|
10
|
+
private envFilename;
|
|
11
|
+
private $provideOrCreateEnvFile;
|
|
12
|
+
private transformKey;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the number of key/value pairs currently present in the list associated with the object.
|
|
15
|
+
*/
|
|
16
|
+
get length(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Empties the list associated with the object of all key/value pairs, if there are any.
|
|
19
|
+
*/
|
|
20
|
+
clear(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
|
|
23
|
+
*/
|
|
24
|
+
getItem(key: string): Promise<TItem | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
|
|
27
|
+
*/
|
|
28
|
+
key(index: number): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
31
|
+
*/
|
|
32
|
+
setItem(key: string, value: TItem): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
|
|
35
|
+
*/
|
|
36
|
+
removeItem(key: string): void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* TODO: Write file more securely - ensure that there can be no accidental overwriting of existing variables and other content
|
|
40
|
+
*/
|
|
@@ -325,6 +325,12 @@ export type string_css_selector = string;
|
|
|
325
325
|
* For example `"https://collboard.com/9SeSQTupmQHwuSrLi"`
|
|
326
326
|
*/
|
|
327
327
|
export type string_url = string;
|
|
328
|
+
/**
|
|
329
|
+
* Semantic helper
|
|
330
|
+
*
|
|
331
|
+
* For example `"https://s1.ptbk.io/promptbook"`
|
|
332
|
+
*/
|
|
333
|
+
export type string_promptbook_server_url = string;
|
|
328
334
|
/**
|
|
329
335
|
* Semantic helper
|
|
330
336
|
*
|
|
@@ -408,6 +414,13 @@ export type string_host = string;
|
|
|
408
414
|
* Semantic helper
|
|
409
415
|
*/
|
|
410
416
|
export type string_protocol = 'http:' | 'https:';
|
|
417
|
+
/**
|
|
418
|
+
* Semantic helper
|
|
419
|
+
*
|
|
420
|
+
* For example `"192.168.1.1"` (IPv4)
|
|
421
|
+
* For example `"2001:0db8:85a3:0000:0000:8a2e:0370:7334"` (IPv6)
|
|
422
|
+
*/
|
|
423
|
+
export type string_ip_address = string;
|
|
411
424
|
/**
|
|
412
425
|
* Semantic helper
|
|
413
426
|
*
|
|
@@ -521,6 +534,13 @@ export type string_person_profile = string;
|
|
|
521
534
|
* For example `"MIT"`
|
|
522
535
|
*/
|
|
523
536
|
export type string_license = string;
|
|
537
|
+
/**
|
|
538
|
+
* Semantic helper
|
|
539
|
+
*
|
|
540
|
+
* For example `"Pavol Hejný <pavol@ptbk.io> (https://www.pavolhejny.com/)"`
|
|
541
|
+
* For example `"AI Web, LLC <legal@ptbk.io> (https://www.ptbk.io/)"`
|
|
542
|
+
*/
|
|
543
|
+
export type string_legal_entity = string | string_person_profile | string_title;
|
|
524
544
|
/**
|
|
525
545
|
* Semantic helper for attributes
|
|
526
546
|
*
|
|
@@ -570,6 +590,12 @@ export type string_postprocessing_function_name = string;
|
|
|
570
590
|
export type id = string | number;
|
|
571
591
|
export type task_id = string;
|
|
572
592
|
export type string_token = string;
|
|
593
|
+
/**
|
|
594
|
+
* Semantic helper
|
|
595
|
+
*
|
|
596
|
+
* Made by `identificationToPromptbookToken` exported from `@promptbook/core`
|
|
597
|
+
*/
|
|
598
|
+
export type string_promptbook_token = string_token;
|
|
573
599
|
export type string_license_token = string_token;
|
|
574
600
|
export type string_password = string;
|
|
575
601
|
export type string_ssh_key = string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/remote-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.92.0-10",
|
|
4
4
|
"description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -43,14 +43,18 @@
|
|
|
43
43
|
"url": "https://github.com/webgptorg/promptbook/issues"
|
|
44
44
|
},
|
|
45
45
|
"homepage": "https://ptbk.io/",
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=16.0.0",
|
|
48
|
+
"npm": ">=8.0.0"
|
|
49
|
+
},
|
|
46
50
|
"main": "./umd/index.umd.js",
|
|
47
51
|
"module": "./esm/index.es.js",
|
|
48
52
|
"typings": "./esm/typings/src/_packages/remote-client.index.d.ts",
|
|
49
53
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.
|
|
54
|
+
"@promptbook/core": "0.92.0-10"
|
|
51
55
|
},
|
|
52
56
|
"dependencies": {
|
|
53
|
-
"crypto": "
|
|
57
|
+
"crypto": "1.0.1",
|
|
54
58
|
"crypto-js": "4.2.0",
|
|
55
59
|
"papaparse": "5.4.1",
|
|
56
60
|
"socket.io-client": "4.7.2",
|
package/umd/index.umd.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* @generated
|
|
24
24
|
* @see https://github.com/webgptorg/promptbook
|
|
25
25
|
*/
|
|
26
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
26
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.92.0-10';
|
|
27
27
|
/**
|
|
28
28
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
29
29
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -241,7 +241,7 @@
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
244
|
-
* TODO:
|
|
244
|
+
* TODO: [🧠][🌂] Add id to all errors
|
|
245
245
|
*/
|
|
246
246
|
|
|
247
247
|
/**
|
|
@@ -323,6 +323,7 @@
|
|
|
323
323
|
* @public exported from `@promptbook/core`
|
|
324
324
|
*/
|
|
325
325
|
const ADMIN_GITHUB_NAME = 'hejny';
|
|
326
|
+
// <- TODO: [🐊] Pick the best claim
|
|
326
327
|
/**
|
|
327
328
|
* When the title is not provided, the default title is used
|
|
328
329
|
*
|
|
@@ -446,6 +447,26 @@
|
|
|
446
447
|
}
|
|
447
448
|
}
|
|
448
449
|
|
|
450
|
+
/**
|
|
451
|
+
* This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
|
|
452
|
+
*
|
|
453
|
+
* @public exported from `@promptbook/core`
|
|
454
|
+
*/
|
|
455
|
+
class WrappedError extends Error {
|
|
456
|
+
constructor(whatWasThrown) {
|
|
457
|
+
const tag = `[🤮]`;
|
|
458
|
+
console.error(tag, whatWasThrown);
|
|
459
|
+
super(spaceTrim.spaceTrim(`
|
|
460
|
+
Non-Error object was thrown
|
|
461
|
+
|
|
462
|
+
Note: Look for ${tag} in the console for more details
|
|
463
|
+
Please report issue on ${ADMIN_EMAIL}
|
|
464
|
+
`));
|
|
465
|
+
this.name = 'WrappedError';
|
|
466
|
+
Object.setPrototypeOf(this, WrappedError.prototype);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
449
470
|
/**
|
|
450
471
|
* Index of all custom errors
|
|
451
472
|
*
|
|
@@ -466,7 +487,10 @@
|
|
|
466
487
|
PipelineExecutionError,
|
|
467
488
|
PipelineLogicError,
|
|
468
489
|
PipelineUrlError,
|
|
490
|
+
AuthenticationError,
|
|
491
|
+
PromptbookFetchError,
|
|
469
492
|
UnexpectedError,
|
|
493
|
+
WrappedError,
|
|
470
494
|
// TODO: [🪑]> VersionMismatchError,
|
|
471
495
|
};
|
|
472
496
|
/**
|
|
@@ -483,8 +507,6 @@
|
|
|
483
507
|
TypeError,
|
|
484
508
|
URIError,
|
|
485
509
|
AggregateError,
|
|
486
|
-
AuthenticationError,
|
|
487
|
-
PromptbookFetchError,
|
|
488
510
|
/*
|
|
489
511
|
Note: Not widely supported
|
|
490
512
|
> InternalError,
|
|
@@ -533,6 +555,35 @@
|
|
|
533
555
|
return deserializedError;
|
|
534
556
|
}
|
|
535
557
|
|
|
558
|
+
/**
|
|
559
|
+
* Tests if given string is valid URL.
|
|
560
|
+
*
|
|
561
|
+
* Note: Dataurl are considered perfectly valid.
|
|
562
|
+
* Note: There are two simmilar functions:
|
|
563
|
+
* - `isValidUrl` which tests any URL
|
|
564
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
565
|
+
*
|
|
566
|
+
* @public exported from `@promptbook/utils`
|
|
567
|
+
*/
|
|
568
|
+
function isValidUrl(url) {
|
|
569
|
+
if (typeof url !== 'string') {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
try {
|
|
573
|
+
if (url.startsWith('blob:')) {
|
|
574
|
+
url = url.replace(/^blob:/, '');
|
|
575
|
+
}
|
|
576
|
+
const urlObject = new URL(url /* because fail is handled */);
|
|
577
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
536
587
|
/**
|
|
537
588
|
* Creates a connection to the remote proxy server.
|
|
538
589
|
*
|
|
@@ -542,17 +593,31 @@
|
|
|
542
593
|
*/
|
|
543
594
|
async function createRemoteClient(options) {
|
|
544
595
|
const { remoteServerUrl } = options;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
596
|
+
if (!isValidUrl(remoteServerUrl)) {
|
|
597
|
+
throw new Error(`Invalid \`remoteServerUrl\`: "${remoteServerUrl}"`);
|
|
598
|
+
}
|
|
599
|
+
const remoteServerUrlParsed = new URL(remoteServerUrl);
|
|
600
|
+
if (remoteServerUrlParsed.pathname !== '/' && remoteServerUrlParsed.pathname !== '') {
|
|
601
|
+
remoteServerUrlParsed.pathname = '/';
|
|
602
|
+
throw new Error(spaceTrim__default["default"]((block) => `
|
|
603
|
+
Remote server requires root url \`/\`
|
|
604
|
+
|
|
605
|
+
You have provided \`remoteServerUrl\`:
|
|
606
|
+
${block(remoteServerUrl)}
|
|
607
|
+
|
|
608
|
+
But something like this is expected:
|
|
609
|
+
${block(remoteServerUrlParsed.href)}
|
|
610
|
+
|
|
611
|
+
Note: If you need to run multiple services on the same server, use 3rd or 4th degree subdomain
|
|
612
|
+
|
|
613
|
+
`));
|
|
548
614
|
}
|
|
549
|
-
path = `${path}/socket.io`;
|
|
550
615
|
return new Promise((resolve, reject) => {
|
|
551
616
|
const socket = socket_ioClient.io(remoteServerUrl, {
|
|
552
617
|
retries: CONNECTION_RETRIES_LIMIT,
|
|
553
618
|
timeout: CONNECTION_TIMEOUT_MS,
|
|
554
|
-
path,
|
|
555
|
-
transports: [
|
|
619
|
+
path: '/socket.io',
|
|
620
|
+
transports: ['polling', 'websocket' /*, <- TODO: [🌬] Allow to pass `transports`, add 'webtransport' */],
|
|
556
621
|
});
|
|
557
622
|
// console.log('Connecting to', this.options.remoteServerUrl.href, { socket });
|
|
558
623
|
socket.on('connect', () => {
|
|
@@ -686,35 +751,6 @@
|
|
|
686
751
|
* TODO: [🍏] Implement for MacOs
|
|
687
752
|
*/
|
|
688
753
|
|
|
689
|
-
/**
|
|
690
|
-
* Tests if given string is valid URL.
|
|
691
|
-
*
|
|
692
|
-
* Note: Dataurl are considered perfectly valid.
|
|
693
|
-
* Note: There are two simmilar functions:
|
|
694
|
-
* - `isValidUrl` which tests any URL
|
|
695
|
-
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
696
|
-
*
|
|
697
|
-
* @public exported from `@promptbook/utils`
|
|
698
|
-
*/
|
|
699
|
-
function isValidUrl(url) {
|
|
700
|
-
if (typeof url !== 'string') {
|
|
701
|
-
return false;
|
|
702
|
-
}
|
|
703
|
-
try {
|
|
704
|
-
if (url.startsWith('blob:')) {
|
|
705
|
-
url = url.replace(/^blob:/, '');
|
|
706
|
-
}
|
|
707
|
-
const urlObject = new URL(url /* because fail is handled */);
|
|
708
|
-
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
709
|
-
return false;
|
|
710
|
-
}
|
|
711
|
-
return true;
|
|
712
|
-
}
|
|
713
|
-
catch (error) {
|
|
714
|
-
return false;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
|
|
718
754
|
const defaultDiacriticsRemovalMap = [
|
|
719
755
|
{
|
|
720
756
|
base: 'A',
|
|
@@ -1542,6 +1578,34 @@
|
|
|
1542
1578
|
},
|
|
1543
1579
|
};
|
|
1544
1580
|
|
|
1581
|
+
/**
|
|
1582
|
+
* Helper used in catch blocks to assert that the error is an instance of `Error`
|
|
1583
|
+
*
|
|
1584
|
+
* @param whatWasThrown Any object that was thrown
|
|
1585
|
+
* @returns Nothing if the error is an instance of `Error`
|
|
1586
|
+
* @throws `WrappedError` or `UnexpectedError` if the error is not standard
|
|
1587
|
+
*
|
|
1588
|
+
* @private within the repository
|
|
1589
|
+
*/
|
|
1590
|
+
function assertsError(whatWasThrown) {
|
|
1591
|
+
// Case 1: Handle error which was rethrown as `WrappedError`
|
|
1592
|
+
if (whatWasThrown instanceof WrappedError) {
|
|
1593
|
+
const wrappedError = whatWasThrown;
|
|
1594
|
+
throw wrappedError;
|
|
1595
|
+
}
|
|
1596
|
+
// Case 2: Handle unexpected errors
|
|
1597
|
+
if (whatWasThrown instanceof UnexpectedError) {
|
|
1598
|
+
const unexpectedError = whatWasThrown;
|
|
1599
|
+
throw unexpectedError;
|
|
1600
|
+
}
|
|
1601
|
+
// Case 3: Handle standard errors - keep them up to consumer
|
|
1602
|
+
if (whatWasThrown instanceof Error) {
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
// Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
|
|
1606
|
+
throw new WrappedError(whatWasThrown);
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1545
1609
|
/**
|
|
1546
1610
|
* Units of text measurement
|
|
1547
1611
|
*
|
|
@@ -1622,6 +1686,8 @@
|
|
|
1622
1686
|
*/
|
|
1623
1687
|
|
|
1624
1688
|
/**
|
|
1689
|
+
import { WrappedError } from '../../errors/WrappedError';
|
|
1690
|
+
import { assertsError } from '../../errors/assertsError';
|
|
1625
1691
|
* Parses the expect command
|
|
1626
1692
|
*
|
|
1627
1693
|
* @see `documentationUrl` for more details
|
|
@@ -1713,9 +1779,7 @@
|
|
|
1713
1779
|
};
|
|
1714
1780
|
}
|
|
1715
1781
|
catch (error) {
|
|
1716
|
-
|
|
1717
|
-
throw error;
|
|
1718
|
-
}
|
|
1782
|
+
assertsError(error);
|
|
1719
1783
|
throw new ParseError(spaceTrim__default["default"]((block) => `
|
|
1720
1784
|
Invalid FORMAT command
|
|
1721
1785
|
${block(error.message)}:
|
|
@@ -1773,6 +1837,46 @@
|
|
|
1773
1837
|
// encoding: 'utf-8',
|
|
1774
1838
|
});
|
|
1775
1839
|
|
|
1840
|
+
/**
|
|
1841
|
+
* Function to check if a string is valid CSV
|
|
1842
|
+
*
|
|
1843
|
+
* @param value The string to check
|
|
1844
|
+
* @returns True if the string is a valid CSV string, false otherwise
|
|
1845
|
+
*
|
|
1846
|
+
* @public exported from `@promptbook/utils`
|
|
1847
|
+
*/
|
|
1848
|
+
function isValidCsvString(value) {
|
|
1849
|
+
try {
|
|
1850
|
+
// A simple check for CSV format: at least one comma and no invalid characters
|
|
1851
|
+
if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
|
|
1852
|
+
return true;
|
|
1853
|
+
}
|
|
1854
|
+
return false;
|
|
1855
|
+
}
|
|
1856
|
+
catch (error) {
|
|
1857
|
+
assertsError(error);
|
|
1858
|
+
return false;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
/**
|
|
1863
|
+
* Converts a CSV string into an object
|
|
1864
|
+
*
|
|
1865
|
+
* Note: This is wrapper around `papaparse.parse()` with better autohealing
|
|
1866
|
+
*
|
|
1867
|
+
* @private - for now until `@promptbook/csv` is released
|
|
1868
|
+
*/
|
|
1869
|
+
function csvParse(value /* <- TODO: string_csv */, settings, schema /* <- TODO: Make CSV Schemas */) {
|
|
1870
|
+
settings = { ...settings, ...MANDATORY_CSV_SETTINGS };
|
|
1871
|
+
// Note: Autoheal invalid '\n' characters
|
|
1872
|
+
if (settings.newline && !settings.newline.includes('\r') && value.includes('\r')) {
|
|
1873
|
+
console.warn('CSV string contains carriage return characters, but in the CSV settings the `newline` setting does not include them. Autohealing the CSV string.');
|
|
1874
|
+
value = value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
1875
|
+
}
|
|
1876
|
+
const csv = papaparse.parse(value, settings);
|
|
1877
|
+
return csv;
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1776
1880
|
/**
|
|
1777
1881
|
* Definition for CSV spreadsheet
|
|
1778
1882
|
*
|
|
@@ -1783,7 +1887,7 @@
|
|
|
1783
1887
|
formatName: 'CSV',
|
|
1784
1888
|
aliases: ['SPREADSHEET', 'TABLE'],
|
|
1785
1889
|
isValid(value, settings, schema) {
|
|
1786
|
-
return
|
|
1890
|
+
return isValidCsvString(value);
|
|
1787
1891
|
},
|
|
1788
1892
|
canBeValid(partialValue, settings, schema) {
|
|
1789
1893
|
return true;
|
|
@@ -1795,8 +1899,7 @@
|
|
|
1795
1899
|
{
|
|
1796
1900
|
subvalueName: 'ROW',
|
|
1797
1901
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
1798
|
-
|
|
1799
|
-
const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
1902
|
+
const csv = csvParse(value, settings);
|
|
1800
1903
|
if (csv.errors.length !== 0) {
|
|
1801
1904
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
1802
1905
|
CSV parsing error
|
|
@@ -1826,8 +1929,7 @@
|
|
|
1826
1929
|
{
|
|
1827
1930
|
subvalueName: 'CELL',
|
|
1828
1931
|
async mapValues(value, outputParameterName, settings, mapCallback) {
|
|
1829
|
-
|
|
1830
|
-
const csv = papaparse.parse(value, { ...settings, ...MANDATORY_CSV_SETTINGS });
|
|
1932
|
+
const csv = csvParse(value, settings);
|
|
1831
1933
|
if (csv.errors.length !== 0) {
|
|
1832
1934
|
throw new CsvFormatError(spaceTrim__default["default"]((block) => `
|
|
1833
1935
|
CSV parsing error
|
|
@@ -1864,6 +1966,9 @@
|
|
|
1864
1966
|
/**
|
|
1865
1967
|
* Function isValidJsonString will tell you if the string is valid JSON or not
|
|
1866
1968
|
*
|
|
1969
|
+
* @param value The string to check
|
|
1970
|
+
* @returns True if the string is a valid JSON string, false otherwise
|
|
1971
|
+
*
|
|
1867
1972
|
* @public exported from `@promptbook/utils`
|
|
1868
1973
|
*/
|
|
1869
1974
|
function isValidJsonString(value /* <- [👨⚖️] */) {
|
|
@@ -1872,9 +1977,7 @@
|
|
|
1872
1977
|
return true;
|
|
1873
1978
|
}
|
|
1874
1979
|
catch (error) {
|
|
1875
|
-
|
|
1876
|
-
throw error;
|
|
1877
|
-
}
|
|
1980
|
+
assertsError(error);
|
|
1878
1981
|
if (error.message.includes('Unexpected token')) {
|
|
1879
1982
|
return false;
|
|
1880
1983
|
}
|
|
@@ -1958,6 +2061,30 @@
|
|
|
1958
2061
|
* TODO: [🏢] Allow to expect something inside each item of list and other formats
|
|
1959
2062
|
*/
|
|
1960
2063
|
|
|
2064
|
+
/**
|
|
2065
|
+
* Function to check if a string is valid XML
|
|
2066
|
+
*
|
|
2067
|
+
* @param value
|
|
2068
|
+
* @returns True if the string is a valid XML string, false otherwise
|
|
2069
|
+
*
|
|
2070
|
+
* @public exported from `@promptbook/utils`
|
|
2071
|
+
*/
|
|
2072
|
+
function isValidXmlString(value) {
|
|
2073
|
+
try {
|
|
2074
|
+
const parser = new DOMParser();
|
|
2075
|
+
const parsedDocument = parser.parseFromString(value, 'application/xml');
|
|
2076
|
+
const parserError = parsedDocument.getElementsByTagName('parsererror');
|
|
2077
|
+
if (parserError.length > 0) {
|
|
2078
|
+
return false;
|
|
2079
|
+
}
|
|
2080
|
+
return true;
|
|
2081
|
+
}
|
|
2082
|
+
catch (error) {
|
|
2083
|
+
assertsError(error);
|
|
2084
|
+
return false;
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
|
|
1961
2088
|
/**
|
|
1962
2089
|
* Definition for XML format
|
|
1963
2090
|
*
|
|
@@ -1967,7 +2094,7 @@
|
|
|
1967
2094
|
formatName: 'XML',
|
|
1968
2095
|
mimeType: 'application/xml',
|
|
1969
2096
|
isValid(value, settings, schema) {
|
|
1970
|
-
return
|
|
2097
|
+
return isValidXmlString(value);
|
|
1971
2098
|
},
|
|
1972
2099
|
canBeValid(partialValue, settings, schema) {
|
|
1973
2100
|
return true;
|
|
@@ -2192,9 +2319,7 @@
|
|
|
2192
2319
|
JSON.stringify(value); // <- TODO: [0]
|
|
2193
2320
|
}
|
|
2194
2321
|
catch (error) {
|
|
2195
|
-
|
|
2196
|
-
throw error;
|
|
2197
|
-
}
|
|
2322
|
+
assertsError(error);
|
|
2198
2323
|
throw new UnexpectedError(spaceTrim__default["default"]((block) => `
|
|
2199
2324
|
\`${name}\` is not serializable
|
|
2200
2325
|
|
|
@@ -4849,9 +4974,7 @@
|
|
|
4849
4974
|
}
|
|
4850
4975
|
}
|
|
4851
4976
|
catch (error) {
|
|
4852
|
-
|
|
4853
|
-
throw error;
|
|
4854
|
-
}
|
|
4977
|
+
assertsError(error);
|
|
4855
4978
|
throw new ParseError(spaceTrim.spaceTrim((block) => `
|
|
4856
4979
|
Can not extract variables from the script
|
|
4857
4980
|
${block(error.stack || error.message)}
|