@promptbook/legacy-documents 0.89.0-9 โ†’ 0.92.0-3

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.
Files changed (41) hide show
  1. package/README.md +9 -7
  2. package/esm/index.es.js +131 -39
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/servers.d.ts +40 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +10 -4
  6. package/esm/typings/src/_packages/types.index.d.ts +18 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  8. package/esm/typings/src/cli/cli-commands/login.d.ts +0 -1
  9. package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +16 -3
  10. package/esm/typings/src/cli/test/ptbk.d.ts +1 -1
  11. package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +2 -0
  12. package/esm/typings/src/config.d.ts +10 -19
  13. package/esm/typings/src/errors/0-index.d.ts +7 -4
  14. package/esm/typings/src/errors/PipelineExecutionError.d.ts +1 -1
  15. package/esm/typings/src/errors/WrappedError.d.ts +10 -0
  16. package/esm/typings/src/errors/assertsError.d.ts +11 -0
  17. package/esm/typings/src/execution/PromptbookFetch.d.ts +1 -1
  18. package/esm/typings/src/formats/csv/utils/isValidCsvString.d.ts +9 -0
  19. package/esm/typings/src/formats/csv/utils/isValidCsvString.test.d.ts +1 -0
  20. package/esm/typings/src/formats/json/utils/isValidJsonString.d.ts +3 -0
  21. package/esm/typings/src/formats/xml/utils/isValidXmlString.d.ts +9 -0
  22. package/esm/typings/src/formats/xml/utils/isValidXmlString.test.d.ts +1 -0
  23. package/esm/typings/src/llm-providers/_common/filterModels.d.ts +15 -0
  24. package/esm/typings/src/llm-providers/_common/register/{$provideEnvFilepath.d.ts โ†’ $provideEnvFilename.d.ts} +2 -2
  25. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +1 -1
  26. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +1 -1
  27. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +11 -2
  28. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -1
  29. package/esm/typings/src/remote-server/openapi-types.d.ts +284 -0
  30. package/esm/typings/src/remote-server/openapi.d.ts +187 -0
  31. package/esm/typings/src/remote-server/socket-types/_subtypes/Identification.d.ts +7 -1
  32. package/esm/typings/src/remote-server/socket-types/_subtypes/identificationToPromptbookToken.d.ts +11 -0
  33. package/esm/typings/src/remote-server/socket-types/_subtypes/promptbookTokenToIdentification.d.ts +10 -0
  34. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  35. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +15 -9
  36. package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +40 -0
  37. package/esm/typings/src/types/typeAliases.d.ts +26 -0
  38. package/package.json +8 -4
  39. package/umd/index.umd.js +131 -39
  40. package/umd/index.umd.js.map +1 -1
  41. package/esm/typings/src/cli/test/ptbk2.d.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/legacy-documents",
3
- "version": "0.89.0-9",
3
+ "version": "0.92.0-3",
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,19 +43,23 @@
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/legacy-documents.index.d.ts",
49
53
  "peerDependencies": {
50
- "@promptbook/core": "0.89.0-9"
54
+ "@promptbook/core": "0.92.0-3"
51
55
  },
52
56
  "dependencies": {
53
57
  "colors": "1.4.0",
54
- "crypto": "^1.0.1",
58
+ "crypto": "1.0.1",
55
59
  "crypto-js": "4.2.0",
56
60
  "papaparse": "5.4.1",
57
61
  "prettier": "2.8.1",
58
- "rxjs": "^7.8.1",
62
+ "rxjs": "7.8.1",
59
63
  "spacetrim": "0.11.59",
60
64
  "waitasecond": "1.11.83"
61
65
  }
package/umd/index.umd.js CHANGED
@@ -26,7 +26,7 @@
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.92.0-3';
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 @@
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 @@
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 @@
160
162
  */
161
163
  const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [๐Ÿคนโ€โ™‚๏ธ]
162
164
  // <- TODO: [๐Ÿ•] Make also `BOOKS_DIRNAME_ALTERNATIVES`
163
- // TODO: !!!!!! Just .promptbook dir, hardocode others
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
  *
@@ -1068,9 +1070,60 @@
1068
1070
  * TODO: Maybe split `ParseError` and `ApplyError`
1069
1071
  */
1070
1072
 
1073
+ /**
1074
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
1075
+ *
1076
+ * @public exported from `@promptbook/core`
1077
+ */
1078
+ class WrappedError extends Error {
1079
+ constructor(whatWasThrown) {
1080
+ const tag = `[๐Ÿคฎ]`;
1081
+ console.error(tag, whatWasThrown);
1082
+ super(spaceTrim.spaceTrim(`
1083
+ Non-Error object was thrown
1084
+
1085
+ Note: Look for ${tag} in the console for more details
1086
+ Please report issue on ${ADMIN_EMAIL}
1087
+ `));
1088
+ this.name = 'WrappedError';
1089
+ Object.setPrototypeOf(this, WrappedError.prototype);
1090
+ }
1091
+ }
1092
+
1093
+ /**
1094
+ * Helper used in catch blocks to assert that the error is an instance of `Error`
1095
+ *
1096
+ * @param whatWasThrown Any object that was thrown
1097
+ * @returns Nothing if the error is an instance of `Error`
1098
+ * @throws `WrappedError` or `UnexpectedError` if the error is not standard
1099
+ *
1100
+ * @private within the repository
1101
+ */
1102
+ function assertsError(whatWasThrown) {
1103
+ // Case 1: Handle error which was rethrown as `WrappedError`
1104
+ if (whatWasThrown instanceof WrappedError) {
1105
+ const wrappedError = whatWasThrown;
1106
+ throw wrappedError;
1107
+ }
1108
+ // Case 2: Handle unexpected errors
1109
+ if (whatWasThrown instanceof UnexpectedError) {
1110
+ const unexpectedError = whatWasThrown;
1111
+ throw unexpectedError;
1112
+ }
1113
+ // Case 3: Handle standard errors - keep them up to consumer
1114
+ if (whatWasThrown instanceof Error) {
1115
+ return;
1116
+ }
1117
+ // Case 4: Handle non-standard errors - wrap them into `WrappedError` and throw
1118
+ throw new WrappedError(whatWasThrown);
1119
+ }
1120
+
1071
1121
  /**
1072
1122
  * Function isValidJsonString will tell you if the string is valid JSON or not
1073
1123
  *
1124
+ * @param value The string to check
1125
+ * @returns True if the string is a valid JSON string, false otherwise
1126
+ *
1074
1127
  * @public exported from `@promptbook/utils`
1075
1128
  */
1076
1129
  function isValidJsonString(value /* <- [๐Ÿ‘จโ€โš–๏ธ] */) {
@@ -1079,9 +1132,7 @@
1079
1132
  return true;
1080
1133
  }
1081
1134
  catch (error) {
1082
- if (!(error instanceof Error)) {
1083
- throw error;
1084
- }
1135
+ assertsError(error);
1085
1136
  if (error.message.includes('Unexpected token')) {
1086
1137
  return false;
1087
1138
  }
@@ -1434,9 +1485,7 @@
1434
1485
  JSON.stringify(value); // <- TODO: [0]
1435
1486
  }
1436
1487
  catch (error) {
1437
- if (!(error instanceof Error)) {
1438
- throw error;
1439
- }
1488
+ assertsError(error);
1440
1489
  throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1441
1490
  \`${name}\` is not serializable
1442
1491
 
@@ -2207,7 +2256,7 @@
2207
2256
  }
2208
2257
  }
2209
2258
  /**
2210
- * TODO: !!!!!! Add id to all errors
2259
+ * TODO: [๐Ÿง ][๐ŸŒ‚] Add id to all errors
2211
2260
  */
2212
2261
 
2213
2262
  /**
@@ -2418,7 +2467,10 @@
2418
2467
  PipelineExecutionError,
2419
2468
  PipelineLogicError,
2420
2469
  PipelineUrlError,
2470
+ AuthenticationError,
2471
+ PromptbookFetchError,
2421
2472
  UnexpectedError,
2473
+ WrappedError,
2422
2474
  // TODO: [๐Ÿช‘]> VersionMismatchError,
2423
2475
  };
2424
2476
  /**
@@ -2435,8 +2487,6 @@
2435
2487
  TypeError,
2436
2488
  URIError,
2437
2489
  AggregateError,
2438
- AuthenticationError,
2439
- PromptbookFetchError,
2440
2490
  /*
2441
2491
  Note: Not widely supported
2442
2492
  > InternalError,
@@ -2559,8 +2609,8 @@
2559
2609
  updatedAt = new Date();
2560
2610
  errors.push(...executionResult.errors);
2561
2611
  warnings.push(...executionResult.warnings);
2562
- // <- TODO: !!! Only unique errors and warnings should be added (or filtered)
2563
- // TODO: [๐Ÿง ] !!! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2612
+ // <- TODO: [๐ŸŒ‚] Only unique errors and warnings should be added (or filtered)
2613
+ // TODO: [๐Ÿง ] !! errors, warning, isSuccessful are redundant both in `ExecutionTask` and `ExecutionTask.currentValue`
2564
2614
  // Also maybe move `ExecutionTask.currentValue.usage` -> `ExecutionTask.usage`
2565
2615
  // And delete `ExecutionTask.currentValue.preparedPipeline`
2566
2616
  assertsTaskSuccessful(executionResult);
@@ -2570,6 +2620,7 @@
2570
2620
  partialResultSubject.next(executionResult);
2571
2621
  }
2572
2622
  catch (error) {
2623
+ assertsError(error);
2573
2624
  status = 'ERROR';
2574
2625
  errors.push(error);
2575
2626
  partialResultSubject.error(error);
@@ -2961,14 +3012,15 @@
2961
3012
  }
2962
3013
  }
2963
3014
  catch (error) {
2964
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
3015
+ assertsError(error);
3016
+ if (error instanceof UnexpectedError) {
2965
3017
  throw error;
2966
3018
  }
2967
3019
  errors.push({ llmExecutionTools, error });
2968
3020
  }
2969
3021
  }
2970
3022
  if (errors.length === 1) {
2971
- throw errors[0];
3023
+ throw errors[0].error;
2972
3024
  }
2973
3025
  else if (errors.length > 1) {
2974
3026
  throw new PipelineExecutionError(
@@ -3413,9 +3465,7 @@
3413
3465
  return await fetch(urlOrRequest, init);
3414
3466
  }
3415
3467
  catch (error) {
3416
- if (!(error instanceof Error)) {
3417
- throw error;
3418
- }
3468
+ assertsError(error);
3419
3469
  let url;
3420
3470
  if (typeof urlOrRequest === 'string') {
3421
3471
  url = urlOrRequest;
@@ -3646,9 +3696,7 @@
3646
3696
  knowledgePreparedUnflatten[index] = pieces;
3647
3697
  }
3648
3698
  catch (error) {
3649
- if (!(error instanceof Error)) {
3650
- throw error;
3651
- }
3699
+ assertsError(error);
3652
3700
  console.warn(error);
3653
3701
  // <- TODO: [๐Ÿฎ] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3654
3702
  }
@@ -3940,13 +3988,19 @@
3940
3988
  return value.toISOString();
3941
3989
  }
3942
3990
  else {
3943
- return JSON.stringify(value);
3991
+ try {
3992
+ return JSON.stringify(value);
3993
+ }
3994
+ catch (error) {
3995
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
3996
+ return VALUE_STRINGS.circular;
3997
+ }
3998
+ throw error;
3999
+ }
3944
4000
  }
3945
4001
  }
3946
4002
  catch (error) {
3947
- if (!(error instanceof Error)) {
3948
- throw error;
3949
- }
4003
+ assertsError(error);
3950
4004
  console.error(error);
3951
4005
  return VALUE_STRINGS.unserializable;
3952
4006
  }
@@ -4003,9 +4057,7 @@
4003
4057
  }
4004
4058
  }
4005
4059
  catch (error) {
4006
- if (!(error instanceof Error)) {
4007
- throw error;
4008
- }
4060
+ assertsError(error);
4009
4061
  throw new ParseError(spaceTrim.spaceTrim((block) => `
4010
4062
  Can not extract variables from the script
4011
4063
  ${block(error.stack || error.message)}
@@ -4124,6 +4176,28 @@
4124
4176
  // encoding: 'utf-8',
4125
4177
  });
4126
4178
 
4179
+ /**
4180
+ * Function to check if a string is valid CSV
4181
+ *
4182
+ * @param value The string to check
4183
+ * @returns True if the string is a valid CSV string, false otherwise
4184
+ *
4185
+ * @public exported from `@promptbook/utils`
4186
+ */
4187
+ function isValidCsvString(value) {
4188
+ try {
4189
+ // A simple check for CSV format: at least one comma and no invalid characters
4190
+ if (value.includes(',') && /^[\w\s,"']+$/.test(value)) {
4191
+ return true;
4192
+ }
4193
+ return false;
4194
+ }
4195
+ catch (error) {
4196
+ assertsError(error);
4197
+ return false;
4198
+ }
4199
+ }
4200
+
4127
4201
  /**
4128
4202
  * Definition for CSV spreadsheet
4129
4203
  *
@@ -4134,7 +4208,7 @@
4134
4208
  formatName: 'CSV',
4135
4209
  aliases: ['SPREADSHEET', 'TABLE'],
4136
4210
  isValid(value, settings, schema) {
4137
- return true;
4211
+ return isValidCsvString(value);
4138
4212
  },
4139
4213
  canBeValid(partialValue, settings, schema) {
4140
4214
  return true;
@@ -4288,6 +4362,30 @@
4288
4362
  * TODO: [๐Ÿข] Allow to expect something inside each item of list and other formats
4289
4363
  */
4290
4364
 
4365
+ /**
4366
+ * Function to check if a string is valid XML
4367
+ *
4368
+ * @param value
4369
+ * @returns True if the string is a valid XML string, false otherwise
4370
+ *
4371
+ * @public exported from `@promptbook/utils`
4372
+ */
4373
+ function isValidXmlString(value) {
4374
+ try {
4375
+ const parser = new DOMParser();
4376
+ const parsedDocument = parser.parseFromString(value, 'application/xml');
4377
+ const parserError = parsedDocument.getElementsByTagName('parsererror');
4378
+ if (parserError.length > 0) {
4379
+ return false;
4380
+ }
4381
+ return true;
4382
+ }
4383
+ catch (error) {
4384
+ assertsError(error);
4385
+ return false;
4386
+ }
4387
+ }
4388
+
4291
4389
  /**
4292
4390
  * Definition for XML format
4293
4391
  *
@@ -4297,7 +4395,7 @@
4297
4395
  formatName: 'XML',
4298
4396
  mimeType: 'application/xml',
4299
4397
  isValid(value, settings, schema) {
4300
- return true;
4398
+ return isValidXmlString(value);
4301
4399
  },
4302
4400
  canBeValid(partialValue, settings, schema) {
4303
4401
  return true;
@@ -4870,9 +4968,7 @@
4870
4968
  break scripts;
4871
4969
  }
4872
4970
  catch (error) {
4873
- if (!(error instanceof Error)) {
4874
- throw error;
4875
- }
4971
+ assertsError(error);
4876
4972
  if (error instanceof UnexpectedError) {
4877
4973
  throw error;
4878
4974
  }
@@ -4942,9 +5038,7 @@
4942
5038
  break scripts;
4943
5039
  }
4944
5040
  catch (error) {
4945
- if (!(error instanceof Error)) {
4946
- throw error;
4947
- }
5041
+ assertsError(error);
4948
5042
  if (error instanceof UnexpectedError) {
4949
5043
  throw error;
4950
5044
  }
@@ -5565,9 +5659,7 @@
5565
5659
  await Promise.all(resolving);
5566
5660
  }
5567
5661
  catch (error /* <- Note: [3] */) {
5568
- if (!(error instanceof Error)) {
5569
- throw error;
5570
- }
5662
+ assertsError(error);
5571
5663
  // Note: No need to rethrow UnexpectedError
5572
5664
  // if (error instanceof UnexpectedError) {
5573
5665
  // Note: Count usage, [๐Ÿง ] Maybe put to separate function executionReportJsonToUsage + DRY [๐Ÿคนโ€โ™‚๏ธ]