@promptbook/browser 0.79.0 → 0.80.0-0

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 (33) hide show
  1. package/README.md +4 -0
  2. package/esm/index.es.js +161 -17
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/books/index.d.ts +6 -6
  5. package/esm/typings/src/_packages/core.index.d.ts +4 -2
  6. package/esm/typings/src/_packages/types.index.d.ts +10 -0
  7. package/esm/typings/src/_packages/utils.index.d.ts +4 -0
  8. package/esm/typings/src/cli/cli-commands/runInteractiveChatbot.d.ts +32 -0
  9. package/esm/typings/src/commands/_common/types/CommandParser.d.ts +3 -0
  10. package/esm/typings/src/config.d.ts +0 -25
  11. package/esm/typings/src/constants.d.ts +35 -0
  12. package/esm/typings/src/conversion/pipelineJsonToString.d.ts +1 -0
  13. package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +1 -0
  14. package/esm/typings/src/high-level-abstractions/_common/HighLevelAbstraction.d.ts +20 -0
  15. package/esm/typings/src/high-level-abstractions/implicit-formfactor/ImplicitFormfactorHla.d.ts +10 -0
  16. package/esm/typings/src/high-level-abstractions/index.d.ts +44 -0
  17. package/esm/typings/src/high-level-abstractions/quick-chatbot/QuickChatbotHla.d.ts +10 -0
  18. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  19. package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -1
  20. package/esm/typings/src/prepare/prepareTasks.d.ts +1 -0
  21. package/esm/typings/src/types/typeAliases.d.ts +1 -1
  22. package/esm/typings/src/utils/normalization/orderJson.d.ts +21 -0
  23. package/esm/typings/src/utils/normalization/orderJson.test.d.ts +4 -0
  24. package/esm/typings/src/utils/organization/keepTypeImported.d.ts +9 -0
  25. package/esm/typings/src/utils/serialization/$deepFreeze.d.ts +1 -1
  26. package/esm/typings/src/utils/serialization/checkSerializableAsJson.d.ts +20 -2
  27. package/esm/typings/src/utils/serialization/deepClone.test.d.ts +1 -0
  28. package/esm/typings/src/utils/serialization/exportJson.d.ts +29 -0
  29. package/esm/typings/src/utils/serialization/isSerializableAsJson.d.ts +2 -1
  30. package/package.json +4 -3
  31. package/umd/index.umd.js +161 -17
  32. package/umd/index.umd.js.map +1 -1
  33. package/esm/typings/src/utils/serialization/$asDeeplyFrozenSerializableJson.d.ts +0 -17
@@ -65,6 +65,7 @@ export type CommonCommandParser<TCommand extends CommandBase> = {
65
65
  * Converts the command back to string
66
66
  *
67
67
  * Note: This is used in `pipelineJsonToString` utility
68
+ * @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
68
69
  */
69
70
  stringify(command: TCommand): string_markdown_text;
70
71
  };
@@ -94,6 +95,7 @@ export type PipelineHeadCommandParser<TCommand extends CommandBase> = CommonComm
94
95
  * Reads the command from the `PipelineJson`
95
96
  *
96
97
  * Note: This is used in `pipelineJsonToString` utility
98
+ * @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
97
99
  */
98
100
  takeFromPipelineJson(pipelineJson: PipelineJson): ReadonlyArray<TCommand>;
99
101
  };
@@ -183,4 +185,5 @@ export type CommandParserInput = {
183
185
  };
184
186
  /**
185
187
  * TODO: [♓️] Add order here
188
+ * TODO: [🧠][🍱] Maybe make some common abstraction between `HighLevelAbstraction` and `CommandParser`
186
189
  */
@@ -162,30 +162,6 @@ export declare const DEFAULT_SCRAPE_CACHE_DIRNAME = "./.promptbook/scrape-cache"
162
162
  * @public exported from `@promptbook/core`
163
163
  */
164
164
  export declare const DEFAULT_PIPELINE_COLLECTION_BASE_FILENAME = "index";
165
- /**
166
- * Nonce which is used for replacing things in strings
167
- *
168
- * @private within the repository
169
- */
170
- export declare const REPLACING_NONCE = "u$k42k%!V2zo34w7Fu#@QUHYPW";
171
- /**
172
- * The names of the parameters that are reserved for special purposes
173
- *
174
- * @public exported from `@promptbook/core`
175
- */
176
- export declare const RESERVED_PARAMETER_NAMES: readonly ["content", "context", "knowledge", "examples", "modelName", "currentDate"];
177
- /**
178
- * @@@
179
- *
180
- * @private within the repository
181
- */
182
- export declare const RESERVED_PARAMETER_MISSING_VALUE: string;
183
- /**
184
- * @@@
185
- *
186
- * @private within the repository
187
- */
188
- export declare const RESERVED_PARAMETER_RESTRICTED: string;
189
165
  /**
190
166
  * The thresholds for the relative time in the `moment` NPM package.
191
167
  *
@@ -246,7 +222,6 @@ export declare const IS_PIPELINE_LOGIC_VALIDATED: boolean;
246
222
  */
247
223
  export declare const IS_COST_PREVENTED: boolean;
248
224
  /**
249
- * TODO: Extract `constants.ts` from `config.ts`
250
225
  * Note: [💞] Ignore a discrepancy between file name and entity name
251
226
  * TODO: [🧠][🧜‍♂️] Maybe join remoteUrl and path into single value
252
227
  */
@@ -0,0 +1,35 @@
1
+ import type { PipelineJson } from './pipeline/PipelineJson/PipelineJson';
2
+ import type { ExportJsonOptions } from './utils/serialization/exportJson';
3
+ /**
4
+ * Order of keys in the pipeline JSON
5
+ *
6
+ * @public exported from `@promptbook/core`
7
+ */
8
+ export declare const ORDER_OF_PIPELINE_JSON: ExportJsonOptions<PipelineJson>['order'];
9
+ /**
10
+ * Nonce which is used for replacing things in strings
11
+ *
12
+ * @private within the repository
13
+ */
14
+ export declare const REPLACING_NONCE = "u$k42k%!V2zo34w7Fu#@QUHYPW";
15
+ /**
16
+ * @@@
17
+ *
18
+ * @private within the repository
19
+ */
20
+ export declare const RESERVED_PARAMETER_MISSING_VALUE: string;
21
+ /**
22
+ * @@@
23
+ *
24
+ * @private within the repository
25
+ */
26
+ export declare const RESERVED_PARAMETER_RESTRICTED: string;
27
+ /**
28
+ * The names of the parameters that are reserved for special purposes
29
+ *
30
+ * @public exported from `@promptbook/core`
31
+ */
32
+ export declare const RESERVED_PARAMETER_NAMES: readonly ["content", "context", "knowledge", "examples", "modelName", "currentDate"];
33
+ /**
34
+ * Note: [💞] Ignore a discrepancy between file name and entity name
35
+ */
@@ -3,6 +3,7 @@ import type { PipelineString } from '../pipeline/PipelineString';
3
3
  /**
4
4
  * Converts promptbook in JSON format to string format
5
5
  *
6
+ * @deprecated TODO: [🥍][🧠] Backup original files in `PipelineJson` same as in Promptbook.studio
6
7
  * @param pipelineJson Promptbook in JSON format (.book.json)
7
8
  * @returns Promptbook in string format (.book.md)
8
9
  * @public exported from `@promptbook/core`
@@ -18,6 +18,7 @@ import type { PipelineString } from '../pipeline/PipelineString';
18
18
  */
19
19
  export declare function pipelineStringToJsonSync(pipelineString: PipelineString): PipelineJson;
20
20
  /**
21
+ * TODO: [🧠] Maybe more things here can be refactored as high-level abstractions
21
22
  * TODO: [main] !!!! Warn if used only sync version
22
23
  * TODO: [🚞] Report here line/column of error
23
24
  * TODO: Use spaceTrim more effectively
@@ -0,0 +1,20 @@
1
+ import type { $PipelineJson } from '../../commands/_common/types/CommandParser';
2
+ /**
3
+ * Used in `pipelineStringToJsonSync`
4
+ *
5
+ * @private
6
+ */
7
+ export type SyncHighLevelAbstraction = {
8
+ type: 'SYNC';
9
+ /**
10
+ * Apply the abstraction to the `pipelineJson`
11
+ *
12
+ * Note: `$` is used to indicate that this function mutates given `pipelineJson`
13
+ */
14
+ $applyToPipelineJson($pipelineJson: $PipelineJson): void;
15
+ };
16
+ /**
17
+ * TODO: [♓️] Add order here
18
+ * TODO: [🧠][🍱] Maybe make some common abstraction between `HighLevelAbstraction` and `CommandParser`
19
+ * Note: [💞] Ignore a discrepancy between file name and entity name
20
+ */
@@ -0,0 +1,10 @@
1
+ import type { $PipelineJson } from '../../commands/_common/types/CommandParser';
2
+ /**
3
+ * Set formfactor based on the pipeline interface e
4
+ *
5
+ * @private
6
+ */
7
+ export declare const ImplicitFormfactorHla: {
8
+ type: "SYNC";
9
+ $applyToPipelineJson($pipelineJson: $PipelineJson): void;
10
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * All high-level abstractions
3
+ *
4
+ * @private internal index of `pipelineStringToJsonSync` (= used for sync) and `preparePipeline` (= used for async)
5
+ */
6
+ export declare const HIGH_LEVEL_ABSTRACTIONS: readonly [{
7
+ type: "SYNC";
8
+ $applyToPipelineJson($pipelineJson: import("type-fest/source/writable-deep").WritableObjectDeep<{
9
+ readonly pipelineUrl?: string | undefined;
10
+ readonly sourceFile?: string | undefined;
11
+ readonly title: string;
12
+ readonly bookVersion?: string | undefined;
13
+ readonly description?: string | undefined;
14
+ readonly parameters: import("../_packages/types.index").ParameterJson[];
15
+ readonly defaultModelRequirements?: Partial<import("../types/ModelRequirements").ModelRequirements> | undefined;
16
+ readonly tasks: import("../_packages/types.index").TaskJson[];
17
+ readonly knowledgeSources: (import("../_packages/types.index").KnowledgeSourceJson | import("../_packages/types.index").KnowledgeSourcePreparedJson)[];
18
+ readonly knowledgePieces: import("../_packages/types.index").KnowledgePiecePreparedJson[];
19
+ readonly personas: (import("../_packages/types.index").PersonaJson | import("../_packages/types.index").PersonaPreparedJson)[];
20
+ readonly preparations: import("../_packages/types.index").PreparationJson[];
21
+ readonly formfactorName?: "CHATBOT" | "GENERATOR" | "GENERIC" | "EXPERIMENTAL_MATCHER" | "SHEETS" | "TRANSLATOR" | undefined;
22
+ }>): void;
23
+ }, {
24
+ type: "SYNC";
25
+ $applyToPipelineJson($pipelineJson: import("type-fest/source/writable-deep").WritableObjectDeep<{
26
+ readonly pipelineUrl?: string | undefined;
27
+ readonly sourceFile?: string | undefined;
28
+ readonly title: string;
29
+ readonly bookVersion?: string | undefined;
30
+ readonly description?: string | undefined;
31
+ readonly parameters: import("../_packages/types.index").ParameterJson[];
32
+ readonly defaultModelRequirements?: Partial<import("../types/ModelRequirements").ModelRequirements> | undefined;
33
+ readonly tasks: import("../_packages/types.index").TaskJson[];
34
+ readonly knowledgeSources: (import("../_packages/types.index").KnowledgeSourceJson | import("../_packages/types.index").KnowledgeSourcePreparedJson)[];
35
+ readonly knowledgePieces: import("../_packages/types.index").KnowledgePiecePreparedJson[];
36
+ readonly personas: (import("../_packages/types.index").PersonaJson | import("../_packages/types.index").PersonaPreparedJson)[];
37
+ readonly preparations: import("../_packages/types.index").PreparationJson[];
38
+ readonly formfactorName?: "CHATBOT" | "GENERATOR" | "GENERIC" | "EXPERIMENTAL_MATCHER" | "SHEETS" | "TRANSLATOR" | undefined;
39
+ }>): void;
40
+ }];
41
+ /**
42
+ * TODO: Test that all sync high-level abstractions are before async high-level abstractions
43
+ * Note: [💞] Ignore a discrepancy between file name and entity name
44
+ */
@@ -0,0 +1,10 @@
1
+ import type { $PipelineJson } from '../../commands/_common/types/CommandParser';
2
+ /**
3
+ * Allow to define chatbot with no need to write full interface
4
+ *
5
+ * @private
6
+ */
7
+ export declare const QuickChatbotHla: {
8
+ type: "SYNC";
9
+ $applyToPipelineJson($pipelineJson: $PipelineJson): void;
10
+ };
@@ -54,7 +54,7 @@ export declare class RemoteLlmExecutionTools<TCustomOptions = undefined> impleme
54
54
  private callCommonModel;
55
55
  }
56
56
  /**
57
- * TODO: Maybe use `$asDeeplyFrozenSerializableJson`
57
+ * TODO: Maybe use `$exportJson`
58
58
  * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
59
59
  * TODO: [🍓] Allow to list compatible models with each variant
60
60
  * TODO: [🗯] RemoteLlmExecutionTools should extend Destroyable and implement IDestroyable
@@ -11,7 +11,7 @@ import type { RemoteServerOptions } from './interfaces/RemoteServerOptions';
11
11
  */
12
12
  export declare function startRemoteServer<TCustomOptions = undefined>(options: RemoteServerOptions<TCustomOptions>): IDestroyable;
13
13
  /**
14
- * TODO: Maybe use `$asDeeplyFrozenSerializableJson`
14
+ * TODO: Maybe use `$exportJson`
15
15
  * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
16
16
  * TODO: [⚖] Expose the collection to be able to connect to same collection via createCollectionFromUrl
17
17
  * TODO: Handle progress - support streaming
@@ -22,6 +22,7 @@ type PreparedTasks = {
22
22
  export declare function prepareTasks(pipeline: PrepareTaskInput, tools: Pick<ExecutionTools, 'llm' | 'fs' | 'scrapers'>, options: PrepareAndScrapeOptions): Promise<PreparedTasks>;
23
23
  export {};
24
24
  /**
25
+ * TODO: [😂] Adding knowledge should be convert to async high-level abstractions, simmilar thing with expectations to sync high-level abstractions
25
26
  * TODO: [🧠] Add context to each task (if missing)
26
27
  * TODO: [🧠] What is better name `prepareTask` or `prepareTaskAndParameters`
27
28
  * TODO: [♨][main] !!! Prepare index the examples and maybe tasks
@@ -1,5 +1,5 @@
1
1
  import type { TupleToUnion } from 'type-fest';
2
- import { RESERVED_PARAMETER_NAMES } from '../config';
2
+ import { RESERVED_PARAMETER_NAMES } from '../constants';
3
3
  /**
4
4
  * Semantic helper
5
5
  */
@@ -0,0 +1,21 @@
1
+ import type { JsonArray, JsonObject } from 'type-fest';
2
+ /**
3
+ * Options for the `orderJson` function
4
+ */
5
+ export type OrderJsonOptions<TObject extends JsonObject | JsonArray> = {
6
+ /**
7
+ * Value to checked, ordered and deeply frozen
8
+ */
9
+ value: TObject;
10
+ /**
11
+ * Order of the object properties
12
+ */
13
+ order: Array<keyof TObject>;
14
+ };
15
+ /**
16
+ * Orders JSON object by keys
17
+ *
18
+ * @returns The same type of object as the input re-ordered
19
+ * @public exported from `@promptbook/utils`
20
+ */
21
+ export declare function orderJson<TObject extends JsonObject | JsonArray>(options: OrderJsonOptions<TObject>): TObject;
@@ -0,0 +1,4 @@
1
+ export {};
2
+ /**
3
+ * TODO: [🧠] Is there a way how to test order of value better way than via `JSON.stringify`
4
+ */
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Just says that the type is used but `organize-imports-cli` does not recognize it.
3
+ * [🤛] This is a workaround for the issue.
4
+ *
5
+ * @param value any values
6
+ * @returns void
7
+ * @private within the repository
8
+ */
9
+ export declare function keepTypeImported<TTypeToKeep>(): void;
@@ -1,6 +1,6 @@
1
1
  import type { ReadonlyDeep } from 'type-fest';
2
2
  /**
3
- * @@@
3
+ * Freezes the given object and all its nested objects recursively
4
4
  *
5
5
  * Note: `$` is used to indicate that this function is not a pure function - it mutates given object
6
6
  * Note: This function mutates the object and returns the original (but mutated-deep-freezed) object
@@ -1,4 +1,22 @@
1
1
  import type { string_name } from '../../types/typeAliases';
2
+ import type { really_unknown } from '../organization/really_unknown';
3
+ /**
4
+ * Options for the `checkSerializableAsJson` function
5
+ */
6
+ export type CheckSerializableAsJsonOptions = {
7
+ /**
8
+ * Value to be checked
9
+ */
10
+ value: really_unknown;
11
+ /**
12
+ * Semantic name of the value for debugging purposes
13
+ */
14
+ name?: string_name;
15
+ /**
16
+ * Message alongside the value for debugging purposes
17
+ */
18
+ message?: string;
19
+ };
2
20
  /**
3
21
  * Checks if the value is [🚉] serializable as JSON
4
22
  * If not, throws an UnexpectedError with a rich error message and tracking
@@ -19,9 +37,9 @@ import type { string_name } from '../../types/typeAliases';
19
37
  * @throws UnexpectedError if the value is not serializable as JSON
20
38
  * @public exported from `@promptbook/utils`
21
39
  */
22
- export declare function checkSerializableAsJson(name: string_name, value: unknown): void;
40
+ export declare function checkSerializableAsJson(options: CheckSerializableAsJsonOptions): void;
23
41
  /**
24
- * TODO: [🧠][🛣] More elegant way to tracking than passing `name`
42
+ * TODO: Can be return type more type-safe? like `asserts options.value is JsonValue`
25
43
  * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
26
44
  * Note: [🐠] This is how `checkSerializableAsJson` + `isSerializableAsJson` together can just retun true/false or rich error message
27
45
  */
@@ -0,0 +1,29 @@
1
+ import type { JsonArray, JsonObject } from 'type-fest';
2
+ import type { OrderJsonOptions } from '../normalization/orderJson';
3
+ import type { CheckSerializableAsJsonOptions } from './checkSerializableAsJson';
4
+ /**
5
+ * Options for the `$exportJson` function
6
+ */
7
+ export type ExportJsonOptions<TObject> = CheckSerializableAsJsonOptions & Partial<Pick<OrderJsonOptions<TObject & (JsonObject | JsonArray)>, 'order'>> & {
8
+ /**
9
+ * Value to be checked, ordered and deeply frozen
10
+ */
11
+ value: TObject;
12
+ };
13
+ /**
14
+ * Utility to export a JSON object from a function
15
+ *
16
+ * 1) Checks if the value is serializable as JSON
17
+ * 2) Makes a deep clone of the object
18
+ * 2) Orders the object properties
19
+ * 2) Deeply freezes the cloned object
20
+ *
21
+ * Note: This function does not mutates the given object
22
+ *
23
+ * @returns The same type of object as the input but read-only and re-ordered
24
+ * @public exported from `@promptbook/utils`
25
+ */
26
+ export declare function exportJson<TObject>(options: ExportJsonOptions<TObject>): TObject;
27
+ /**
28
+ * TODO: [🧠] Is there a way how to meaningfully test this utility
29
+ */
@@ -1,3 +1,4 @@
1
+ import { JsonValue } from 'type-fest';
1
2
  /**
2
3
  * Tests if the value is [🚉] serializable as JSON
3
4
  *
@@ -17,7 +18,7 @@
17
18
  *
18
19
  * @public exported from `@promptbook/utils`
19
20
  */
20
- export declare function isSerializableAsJson(value: unknown): boolean;
21
+ export declare function isSerializableAsJson(value: unknown): value is JsonValue;
21
22
  /**
22
23
  * TODO: [🧠][main] !!! In-memory cache of same values to prevent multiple checks
23
24
  * TODO: [🧠][💺] Can be done this on type-level?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/browser",
3
- "version": "0.79.0",
3
+ "version": "0.80.0-0",
4
4
  "description": "It's time for a paradigm shift. The future of software in plain English, French or Latin",
5
5
  "--note-0": " <- [🐊]",
6
6
  "private": false,
@@ -54,9 +54,10 @@
54
54
  "module": "./esm/index.es.js",
55
55
  "typings": "./esm/typings/src/_packages/browser.index.d.ts",
56
56
  "peerDependencies": {
57
- "@promptbook/core": "0.79.0"
57
+ "@promptbook/core": "0.80.0-0"
58
58
  },
59
59
  "dependencies": {
60
- "spacetrim": "0.11.59"
60
+ "spacetrim": "0.11.59",
61
+ "type-fest": "4.5.0"
61
62
  }
62
63
  }