@promptbook/pdf 0.89.0-11 โ†’ 0.89.0-13

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.
@@ -62,6 +62,7 @@ import { PipelineLogicError } from '../errors/PipelineLogicError';
62
62
  import { PipelineUrlError } from '../errors/PipelineUrlError';
63
63
  import { PromptbookFetchError } from '../errors/PromptbookFetchError';
64
64
  import { UnexpectedError } from '../errors/UnexpectedError';
65
+ import { WrappedError } from '../errors/WrappedError';
65
66
  import { createPipelineExecutor } from '../execution/createPipelineExecutor/00-createPipelineExecutor';
66
67
  import { embeddingVectorToString } from '../execution/embeddingVectorToString';
67
68
  import { executionReportJsonToString } from '../execution/execution-report/executionReportJsonToString';
@@ -198,6 +199,7 @@ export { PipelineLogicError };
198
199
  export { PipelineUrlError };
199
200
  export { PromptbookFetchError };
200
201
  export { UnexpectedError };
202
+ export { WrappedError };
201
203
  export { createPipelineExecutor };
202
204
  export { embeddingVectorToString };
203
205
  export { executionReportJsonToString };
@@ -2,4 +2,4 @@
2
2
  /**
3
3
  * Note: [๐Ÿ”บ] Purpose of this file is to test and use the current CLI in development environment
4
4
  */
5
- import '../../_packages/cli.index.ts';
5
+ import '../../_packages/cli.index';
@@ -1,6 +1,8 @@
1
1
  import type { PipelineTaskCommandParser } from '../_common/types/CommandParser';
2
2
  import type { ExpectCommand } from './ExpectCommand';
3
3
  /**
4
+ import { WrappedError } from '../../errors/WrappedError';
5
+ import { assertsError } from '../../errors/assertsError';
4
6
  * Parses the expect command
5
7
  *
6
8
  * @see `documentationUrl` for more details
@@ -115,6 +115,7 @@ export declare const VALUE_STRINGS: {
115
115
  readonly infinity: "(infinity; โˆž)";
116
116
  readonly negativeInfinity: "(negative infinity; -โˆž)";
117
117
  readonly unserializable: "(unserializable value)";
118
+ readonly circular: "(circular JSON)";
118
119
  };
119
120
  /**
120
121
  * Small number limit
@@ -15,6 +15,7 @@ import { PipelineLogicError } from './PipelineLogicError';
15
15
  import { PipelineUrlError } from './PipelineUrlError';
16
16
  import { PromptbookFetchError } from './PromptbookFetchError';
17
17
  import { UnexpectedError } from './UnexpectedError';
18
+ import { WrappedError } from './WrappedError';
18
19
  /**
19
20
  * Index of all custom errors
20
21
  *
@@ -35,7 +36,10 @@ export declare const PROMPTBOOK_ERRORS: {
35
36
  readonly PipelineExecutionError: typeof PipelineExecutionError;
36
37
  readonly PipelineLogicError: typeof PipelineLogicError;
37
38
  readonly PipelineUrlError: typeof PipelineUrlError;
39
+ readonly AuthenticationError: typeof AuthenticationError;
40
+ readonly PromptbookFetchError: typeof PromptbookFetchError;
38
41
  readonly UnexpectedError: typeof UnexpectedError;
42
+ readonly WrappedError: typeof WrappedError;
39
43
  };
40
44
  /**
41
45
  * Index of all javascript errors
@@ -51,8 +55,6 @@ export declare const COMMON_JAVASCRIPT_ERRORS: {
51
55
  readonly TypeError: TypeErrorConstructor;
52
56
  readonly URIError: URIErrorConstructor;
53
57
  readonly AggregateError: AggregateErrorConstructor;
54
- readonly AuthenticationError: typeof AuthenticationError;
55
- readonly PromptbookFetchError: typeof PromptbookFetchError;
56
58
  };
57
59
  /**
58
60
  * Index of all errors
@@ -68,8 +70,6 @@ export declare const ALL_ERRORS: {
68
70
  readonly TypeError: TypeErrorConstructor;
69
71
  readonly URIError: URIErrorConstructor;
70
72
  readonly AggregateError: AggregateErrorConstructor;
71
- readonly AuthenticationError: typeof AuthenticationError;
72
- readonly PromptbookFetchError: typeof PromptbookFetchError;
73
73
  readonly AbstractFormatError: typeof AbstractFormatError;
74
74
  readonly CsvFormatError: typeof CsvFormatError;
75
75
  readonly CollectionError: typeof CollectionError;
@@ -84,7 +84,10 @@ export declare const ALL_ERRORS: {
84
84
  readonly PipelineExecutionError: typeof PipelineExecutionError;
85
85
  readonly PipelineLogicError: typeof PipelineLogicError;
86
86
  readonly PipelineUrlError: typeof PipelineUrlError;
87
+ readonly AuthenticationError: typeof AuthenticationError;
88
+ readonly PromptbookFetchError: typeof PromptbookFetchError;
87
89
  readonly UnexpectedError: typeof UnexpectedError;
90
+ readonly WrappedError: typeof WrappedError;
88
91
  };
89
92
  /**
90
93
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -0,0 +1,10 @@
1
+ import type { really_any } from '../utils/organization/really_any';
2
+ /**
3
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
4
+ *
5
+ * @public exported from `@promptbook/core`
6
+ */
7
+ export declare class WrappedError extends Error {
8
+ readonly name = "WrappedError";
9
+ constructor(whatWasThrown: really_any);
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { really_unknown } from '../utils/organization/really_unknown';
2
+ /**
3
+ * !!!@@@
4
+ *
5
+ * @param whatWasThrown !!!@@@
6
+ * @returns !!!@@@
7
+ *
8
+ * @private within the repository
9
+ */
10
+ export declare function assertsError(whatWasThrown: really_unknown): asserts whatWasThrown is Error;
@@ -7,6 +7,6 @@ import type { string_url } from '../types/typeAliases';
7
7
  *
8
8
  * It is used in theese places:
9
9
  * - Fetching knowledge sources
10
- * - Callbacks from remote server ([๐Ÿ‘ฉ๐Ÿพโ€๐Ÿคโ€๐Ÿง‘๐Ÿพ] Not yet implemented)
10
+ * - Callbacks from remote server
11
11
  */
12
12
  export type PromptbookFetch = (url: string_url, init?: RequestInit) => Promise<Response>;
@@ -12,7 +12,6 @@ import type { RemoteServerOptions } from './types/RemoteServerOptions';
12
12
  export declare function startRemoteServer<TCustomOptions = undefined>(options: RemoteServerOptions<TCustomOptions>): RemoteServer;
13
13
  /**
14
14
  * TODO: !! Add CORS and security - probbably via `helmet`
15
- * TODO: [๐Ÿ‘ฉ๐Ÿพโ€๐Ÿคโ€๐Ÿง‘๐Ÿพ] Allow to pass custom fetch function here - PromptbookFetch
16
15
  * TODO: Split this file into multiple functions - handler for each request
17
16
  * TODO: Maybe use `$exportJson`
18
17
  * TODO: [๐Ÿง ][๐Ÿ›] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
@@ -3,12 +3,14 @@ import type { Promisable } from 'type-fest';
3
3
  import type { PipelineCollection } from '../../collection/PipelineCollection';
4
4
  import { AuthenticationError } from '../../errors/AuthenticationError';
5
5
  import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
6
+ import type { ExecutionTools } from '../../execution/ExecutionTools';
6
7
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
7
8
  import type { string_app_id } from '../../types/typeAliases';
8
9
  import type { string_email } from '../../types/typeAliases';
9
10
  import type { string_password } from '../../types/typeAliases';
10
11
  import type { string_uri } from '../../types/typeAliases';
11
12
  import type { string_user_id } from '../../types/typeAliases';
13
+ import type { ApplicationModeIdentification } from '../socket-types/_subtypes/Identification';
12
14
  import type { Identification } from '../socket-types/_subtypes/Identification';
13
15
  /**
14
16
  * @@@
@@ -37,6 +39,19 @@ export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
37
39
  * @example '/api/promptbook/'
38
40
  */
39
41
  readonly rootPath?: string_uri;
42
+ /**
43
+ * Creates execution tools the client
44
+ *
45
+ * This is relevant also in anonymous mode in oposition to `createLlmExecutionTools`
46
+ *
47
+ * Note: You can provide only some tools and leave the rest to the default ones also llm tools are created by `createLlmExecutionTools`
48
+ * Note: This is useful when you want to provide some custom restrictions for example:
49
+ * - Limit access to certain websites for some users
50
+ * - Bind user-interface tools to email agent
51
+ * - Allow / block script execution
52
+ * - And many more
53
+ */
54
+ createExecutionTools?(options: Identification<TCustomOptions>): Promisable<Partial<Omit<ExecutionTools, 'llm'>>>;
40
55
  } & ((AnonymousRemoteServerOptions & {
41
56
  readonly isApplicationModeAllowed?: false;
42
57
  }) | ({
@@ -74,7 +89,7 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
74
89
  /**
75
90
  * Creates llm execution tools for each client
76
91
  */
77
- createLlmExecutionTools(options: ApplicationRemoteServerClientOptions<TCustomOptions>): Promisable<LlmExecutionTools>;
92
+ createLlmExecutionTools(options: ApplicationModeIdentification<TCustomOptions>): Promisable<LlmExecutionTools>;
78
93
  };
79
94
  export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
80
95
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/pdf",
3
- "version": "0.89.0-11",
3
+ "version": "0.89.0-13",
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,
@@ -47,7 +47,7 @@
47
47
  "module": "./esm/index.es.js",
48
48
  "typings": "./esm/typings/src/_packages/pdf.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.89.0-11"
50
+ "@promptbook/core": "0.89.0-13"
51
51
  },
52
52
  "dependencies": {
53
53
  "crypto": "^1.0.1",
package/umd/index.umd.js CHANGED
@@ -25,7 +25,7 @@
25
25
  * @generated
26
26
  * @see https://github.com/webgptorg/promptbook
27
27
  */
28
- const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-13';
29
29
  /**
30
30
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
31
31
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -120,6 +120,7 @@
120
120
  infinity: '(infinity; โˆž)',
121
121
  negativeInfinity: '(negative infinity; -โˆž)',
122
122
  unserializable: '(unserializable value)',
123
+ circular: '(circular JSON)',
123
124
  };
124
125
  /**
125
126
  * Small number limit
@@ -890,6 +891,56 @@
890
891
  * TODO: Maybe split `ParseError` and `ApplyError`
891
892
  */
892
893
 
894
+ /**
895
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
896
+ *
897
+ * @public exported from `@promptbook/core`
898
+ */
899
+ class WrappedError extends Error {
900
+ constructor(whatWasThrown) {
901
+ const tag = `[๐Ÿคฎ]`;
902
+ console.error(tag, whatWasThrown);
903
+ super(spaceTrim.spaceTrim((block) => `
904
+ ${ /* Fixing tests !!! block(valueToString(whatWasThrown)) */block(`non-Error object was thrown`)}
905
+
906
+ Note: Look for ${tag} in the console for more details
907
+ !!! Note: \`WrappedError\` indicates that somewhere in the code non-Error object was thrown and it was wrapped
908
+
909
+ Please report issue on ${ADMIN_EMAIL}
910
+
911
+ `));
912
+ this.name = 'WrappedError';
913
+ Object.setPrototypeOf(this, WrappedError.prototype);
914
+ }
915
+ }
916
+
917
+ /**
918
+ * !!!@@@
919
+ *
920
+ * @param whatWasThrown !!!@@@
921
+ * @returns !!!@@@
922
+ *
923
+ * @private within the repository
924
+ */
925
+ function assertsError(whatWasThrown) {
926
+ // Case 1: !!!@@@
927
+ if (whatWasThrown instanceof WrappedError) {
928
+ const wrappedError = whatWasThrown;
929
+ throw wrappedError;
930
+ }
931
+ // Case 2: !!!@@@
932
+ if (whatWasThrown instanceof UnexpectedError) {
933
+ const unexpectedError = whatWasThrown;
934
+ throw unexpectedError;
935
+ }
936
+ // Case 3: !!!@@@
937
+ if (whatWasThrown instanceof Error) {
938
+ return;
939
+ }
940
+ // Case 4: !!!@@@
941
+ throw new WrappedError(whatWasThrown);
942
+ }
943
+
893
944
  /**
894
945
  * Function isValidJsonString will tell you if the string is valid JSON or not
895
946
  *
@@ -901,9 +952,7 @@
901
952
  return true;
902
953
  }
903
954
  catch (error) {
904
- if (!(error instanceof Error)) {
905
- throw error;
906
- }
955
+ assertsError(error);
907
956
  if (error.message.includes('Unexpected token')) {
908
957
  return false;
909
958
  }
@@ -1256,9 +1305,7 @@
1256
1305
  JSON.stringify(value); // <- TODO: [0]
1257
1306
  }
1258
1307
  catch (error) {
1259
- if (!(error instanceof Error)) {
1260
- throw error;
1261
- }
1308
+ assertsError(error);
1262
1309
  throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1263
1310
  \`${name}\` is not serializable
1264
1311
 
@@ -2258,7 +2305,10 @@
2258
2305
  PipelineExecutionError,
2259
2306
  PipelineLogicError,
2260
2307
  PipelineUrlError,
2308
+ AuthenticationError,
2309
+ PromptbookFetchError,
2261
2310
  UnexpectedError,
2311
+ WrappedError,
2262
2312
  // TODO: [๐Ÿช‘]> VersionMismatchError,
2263
2313
  };
2264
2314
  /**
@@ -2275,8 +2325,6 @@
2275
2325
  TypeError,
2276
2326
  URIError,
2277
2327
  AggregateError,
2278
- AuthenticationError,
2279
- PromptbookFetchError,
2280
2328
  /*
2281
2329
  Note: Not widely supported
2282
2330
  > InternalError,
@@ -2410,6 +2458,7 @@
2410
2458
  partialResultSubject.next(executionResult);
2411
2459
  }
2412
2460
  catch (error) {
2461
+ assertsError(error);
2413
2462
  status = 'ERROR';
2414
2463
  errors.push(error);
2415
2464
  partialResultSubject.error(error);
@@ -2801,14 +2850,15 @@
2801
2850
  }
2802
2851
  }
2803
2852
  catch (error) {
2804
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
2853
+ assertsError(error);
2854
+ if (error instanceof UnexpectedError) {
2805
2855
  throw error;
2806
2856
  }
2807
2857
  errors.push({ llmExecutionTools, error });
2808
2858
  }
2809
2859
  }
2810
2860
  if (errors.length === 1) {
2811
- throw errors[0];
2861
+ throw errors[0].error;
2812
2862
  }
2813
2863
  else if (errors.length > 1) {
2814
2864
  throw new PipelineExecutionError(
@@ -3263,9 +3313,7 @@
3263
3313
  return await fetch(urlOrRequest, init);
3264
3314
  }
3265
3315
  catch (error) {
3266
- if (!(error instanceof Error)) {
3267
- throw error;
3268
- }
3316
+ assertsError(error);
3269
3317
  let url;
3270
3318
  if (typeof urlOrRequest === 'string') {
3271
3319
  url = urlOrRequest;
@@ -3496,9 +3544,7 @@
3496
3544
  knowledgePreparedUnflatten[index] = pieces;
3497
3545
  }
3498
3546
  catch (error) {
3499
- if (!(error instanceof Error)) {
3500
- throw error;
3501
- }
3547
+ assertsError(error);
3502
3548
  console.warn(error);
3503
3549
  // <- TODO: [๐Ÿฎ] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3504
3550
  }
@@ -3790,13 +3836,19 @@
3790
3836
  return value.toISOString();
3791
3837
  }
3792
3838
  else {
3793
- return JSON.stringify(value);
3839
+ try {
3840
+ return JSON.stringify(value);
3841
+ }
3842
+ catch (error) {
3843
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
3844
+ return VALUE_STRINGS.circular;
3845
+ }
3846
+ throw error;
3847
+ }
3794
3848
  }
3795
3849
  }
3796
3850
  catch (error) {
3797
- if (!(error instanceof Error)) {
3798
- throw error;
3799
- }
3851
+ assertsError(error);
3800
3852
  console.error(error);
3801
3853
  return VALUE_STRINGS.unserializable;
3802
3854
  }
@@ -3853,9 +3905,7 @@
3853
3905
  }
3854
3906
  }
3855
3907
  catch (error) {
3856
- if (!(error instanceof Error)) {
3857
- throw error;
3858
- }
3908
+ assertsError(error);
3859
3909
  throw new ParseError(spaceTrim.spaceTrim((block) => `
3860
3910
  Can not extract variables from the script
3861
3911
  ${block(error.stack || error.message)}
@@ -4720,9 +4770,7 @@
4720
4770
  break scripts;
4721
4771
  }
4722
4772
  catch (error) {
4723
- if (!(error instanceof Error)) {
4724
- throw error;
4725
- }
4773
+ assertsError(error);
4726
4774
  if (error instanceof UnexpectedError) {
4727
4775
  throw error;
4728
4776
  }
@@ -4792,9 +4840,7 @@
4792
4840
  break scripts;
4793
4841
  }
4794
4842
  catch (error) {
4795
- if (!(error instanceof Error)) {
4796
- throw error;
4797
- }
4843
+ assertsError(error);
4798
4844
  if (error instanceof UnexpectedError) {
4799
4845
  throw error;
4800
4846
  }
@@ -5415,9 +5461,7 @@
5415
5461
  await Promise.all(resolving);
5416
5462
  }
5417
5463
  catch (error /* <- Note: [3] */) {
5418
- if (!(error instanceof Error)) {
5419
- throw error;
5420
- }
5464
+ assertsError(error);
5421
5465
  // Note: No need to rethrow UnexpectedError
5422
5466
  // if (error instanceof UnexpectedError) {
5423
5467
  // Note: Count usage, [๐Ÿง ] Maybe put to separate function executionReportJsonToUsage + DRY [๐Ÿคนโ€โ™‚๏ธ]