@promptbook/documents 0.89.0-11 โ†’ 0.89.0-14

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/documents",
3
- "version": "0.89.0-11",
3
+ "version": "0.89.0-14",
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/documents.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.89.0-11"
50
+ "@promptbook/core": "0.89.0-14"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
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-11';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-14';
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
@@ -121,6 +121,7 @@
121
121
  infinity: '(infinity; โˆž)',
122
122
  negativeInfinity: '(negative infinity; -โˆž)',
123
123
  unserializable: '(unserializable value)',
124
+ circular: '(circular JSON)',
124
125
  };
125
126
  /**
126
127
  * Small number limit
@@ -1068,6 +1069,56 @@
1068
1069
  * TODO: Maybe split `ParseError` and `ApplyError`
1069
1070
  */
1070
1071
 
1072
+ /**
1073
+ * This error type indicates that somewhere in the code non-Error object was thrown and it was wrapped into the `WrappedError`
1074
+ *
1075
+ * @public exported from `@promptbook/core`
1076
+ */
1077
+ class WrappedError extends Error {
1078
+ constructor(whatWasThrown) {
1079
+ const tag = `[๐Ÿคฎ]`;
1080
+ console.error(tag, whatWasThrown);
1081
+ super(spaceTrim.spaceTrim((block) => `
1082
+ ${ /* Fixing tests !!! block(valueToString(whatWasThrown)) */block(`non-Error object was thrown`)}
1083
+
1084
+ Note: Look for ${tag} in the console for more details
1085
+ !!! Note: \`WrappedError\` indicates that somewhere in the code non-Error object was thrown and it was wrapped
1086
+
1087
+ Please report issue on ${ADMIN_EMAIL}
1088
+
1089
+ `));
1090
+ this.name = 'WrappedError';
1091
+ Object.setPrototypeOf(this, WrappedError.prototype);
1092
+ }
1093
+ }
1094
+
1095
+ /**
1096
+ * !!!@@@
1097
+ *
1098
+ * @param whatWasThrown !!!@@@
1099
+ * @returns !!!@@@
1100
+ *
1101
+ * @private within the repository
1102
+ */
1103
+ function assertsError(whatWasThrown) {
1104
+ // Case 1: !!!@@@
1105
+ if (whatWasThrown instanceof WrappedError) {
1106
+ const wrappedError = whatWasThrown;
1107
+ throw wrappedError;
1108
+ }
1109
+ // Case 2: !!!@@@
1110
+ if (whatWasThrown instanceof UnexpectedError) {
1111
+ const unexpectedError = whatWasThrown;
1112
+ throw unexpectedError;
1113
+ }
1114
+ // Case 3: !!!@@@
1115
+ if (whatWasThrown instanceof Error) {
1116
+ return;
1117
+ }
1118
+ // Case 4: !!!@@@
1119
+ throw new WrappedError(whatWasThrown);
1120
+ }
1121
+
1071
1122
  /**
1072
1123
  * Function isValidJsonString will tell you if the string is valid JSON or not
1073
1124
  *
@@ -1079,9 +1130,7 @@
1079
1130
  return true;
1080
1131
  }
1081
1132
  catch (error) {
1082
- if (!(error instanceof Error)) {
1083
- throw error;
1084
- }
1133
+ assertsError(error);
1085
1134
  if (error.message.includes('Unexpected token')) {
1086
1135
  return false;
1087
1136
  }
@@ -1434,9 +1483,7 @@
1434
1483
  JSON.stringify(value); // <- TODO: [0]
1435
1484
  }
1436
1485
  catch (error) {
1437
- if (!(error instanceof Error)) {
1438
- throw error;
1439
- }
1486
+ assertsError(error);
1440
1487
  throw new UnexpectedError(spaceTrim__default["default"]((block) => `
1441
1488
  \`${name}\` is not serializable
1442
1489
 
@@ -2418,7 +2465,10 @@
2418
2465
  PipelineExecutionError,
2419
2466
  PipelineLogicError,
2420
2467
  PipelineUrlError,
2468
+ AuthenticationError,
2469
+ PromptbookFetchError,
2421
2470
  UnexpectedError,
2471
+ WrappedError,
2422
2472
  // TODO: [๐Ÿช‘]> VersionMismatchError,
2423
2473
  };
2424
2474
  /**
@@ -2435,8 +2485,6 @@
2435
2485
  TypeError,
2436
2486
  URIError,
2437
2487
  AggregateError,
2438
- AuthenticationError,
2439
- PromptbookFetchError,
2440
2488
  /*
2441
2489
  Note: Not widely supported
2442
2490
  > InternalError,
@@ -2570,6 +2618,7 @@
2570
2618
  partialResultSubject.next(executionResult);
2571
2619
  }
2572
2620
  catch (error) {
2621
+ assertsError(error);
2573
2622
  status = 'ERROR';
2574
2623
  errors.push(error);
2575
2624
  partialResultSubject.error(error);
@@ -2961,14 +3010,15 @@
2961
3010
  }
2962
3011
  }
2963
3012
  catch (error) {
2964
- if (!(error instanceof Error) || error instanceof UnexpectedError) {
3013
+ assertsError(error);
3014
+ if (error instanceof UnexpectedError) {
2965
3015
  throw error;
2966
3016
  }
2967
3017
  errors.push({ llmExecutionTools, error });
2968
3018
  }
2969
3019
  }
2970
3020
  if (errors.length === 1) {
2971
- throw errors[0];
3021
+ throw errors[0].error;
2972
3022
  }
2973
3023
  else if (errors.length > 1) {
2974
3024
  throw new PipelineExecutionError(
@@ -3413,9 +3463,7 @@
3413
3463
  return await fetch(urlOrRequest, init);
3414
3464
  }
3415
3465
  catch (error) {
3416
- if (!(error instanceof Error)) {
3417
- throw error;
3418
- }
3466
+ assertsError(error);
3419
3467
  let url;
3420
3468
  if (typeof urlOrRequest === 'string') {
3421
3469
  url = urlOrRequest;
@@ -3646,9 +3694,7 @@
3646
3694
  knowledgePreparedUnflatten[index] = pieces;
3647
3695
  }
3648
3696
  catch (error) {
3649
- if (!(error instanceof Error)) {
3650
- throw error;
3651
- }
3697
+ assertsError(error);
3652
3698
  console.warn(error);
3653
3699
  // <- TODO: [๐Ÿฎ] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
3654
3700
  }
@@ -3940,13 +3986,19 @@
3940
3986
  return value.toISOString();
3941
3987
  }
3942
3988
  else {
3943
- return JSON.stringify(value);
3989
+ try {
3990
+ return JSON.stringify(value);
3991
+ }
3992
+ catch (error) {
3993
+ if (error instanceof TypeError && error.message.includes('circular structure')) {
3994
+ return VALUE_STRINGS.circular;
3995
+ }
3996
+ throw error;
3997
+ }
3944
3998
  }
3945
3999
  }
3946
4000
  catch (error) {
3947
- if (!(error instanceof Error)) {
3948
- throw error;
3949
- }
4001
+ assertsError(error);
3950
4002
  console.error(error);
3951
4003
  return VALUE_STRINGS.unserializable;
3952
4004
  }
@@ -4003,9 +4055,7 @@
4003
4055
  }
4004
4056
  }
4005
4057
  catch (error) {
4006
- if (!(error instanceof Error)) {
4007
- throw error;
4008
- }
4058
+ assertsError(error);
4009
4059
  throw new ParseError(spaceTrim.spaceTrim((block) => `
4010
4060
  Can not extract variables from the script
4011
4061
  ${block(error.stack || error.message)}
@@ -4870,9 +4920,7 @@
4870
4920
  break scripts;
4871
4921
  }
4872
4922
  catch (error) {
4873
- if (!(error instanceof Error)) {
4874
- throw error;
4875
- }
4923
+ assertsError(error);
4876
4924
  if (error instanceof UnexpectedError) {
4877
4925
  throw error;
4878
4926
  }
@@ -4942,9 +4990,7 @@
4942
4990
  break scripts;
4943
4991
  }
4944
4992
  catch (error) {
4945
- if (!(error instanceof Error)) {
4946
- throw error;
4947
- }
4993
+ assertsError(error);
4948
4994
  if (error instanceof UnexpectedError) {
4949
4995
  throw error;
4950
4996
  }
@@ -5565,9 +5611,7 @@
5565
5611
  await Promise.all(resolving);
5566
5612
  }
5567
5613
  catch (error /* <- Note: [3] */) {
5568
- if (!(error instanceof Error)) {
5569
- throw error;
5570
- }
5614
+ assertsError(error);
5571
5615
  // Note: No need to rethrow UnexpectedError
5572
5616
  // if (error instanceof UnexpectedError) {
5573
5617
  // Note: Count usage, [๐Ÿง ] Maybe put to separate function executionReportJsonToUsage + DRY [๐Ÿคนโ€โ™‚๏ธ]