@promptbook/openai 0.84.0 → 0.85.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 +11 -15
  2. package/esm/index.es.js +3 -3
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +0 -2
  5. package/esm/typings/src/_packages/types.index.d.ts +14 -2
  6. package/esm/typings/src/_packages/utils.index.d.ts +0 -2
  7. package/esm/typings/src/cli/cli-commands/_boilerplate.d.ts +13 -0
  8. package/esm/typings/src/cli/cli-commands/start-server.d.ts +13 -0
  9. package/esm/typings/src/conversion/compilePipelineOnRemoteServer.d.ts +1 -1
  10. package/esm/typings/src/execution/AbstractTaskResult.d.ts +25 -0
  11. package/esm/typings/src/execution/ExecutionTask.d.ts +71 -0
  12. package/esm/typings/src/execution/PipelineExecutor.d.ts +2 -5
  13. package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -15
  14. package/esm/typings/src/execution/PromptbookFetch.d.ts +8 -1
  15. package/esm/typings/src/execution/{assertsExecutionSuccessful.d.ts → assertsTaskSuccessful.d.ts} +2 -3
  16. package/esm/typings/src/execution/createPipelineExecutor/00-createPipelineExecutor.d.ts +0 -3
  17. package/esm/typings/src/execution/createPipelineExecutor/10-executePipeline.d.ts +2 -6
  18. package/esm/typings/src/execution/createPipelineExecutor/20-executeTask.d.ts +3 -6
  19. package/esm/typings/src/prepare/preparePipelineOnRemoteServer.d.ts +1 -1
  20. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -0
  21. package/esm/typings/src/types/typeAliases.d.ts +2 -0
  22. package/esm/typings/src/utils/environment/$isRunningInBrowser.d.ts +2 -2
  23. package/esm/typings/src/utils/environment/$isRunningInJest.d.ts +2 -2
  24. package/esm/typings/src/utils/environment/$isRunningInNode.d.ts +2 -2
  25. package/esm/typings/src/utils/environment/$isRunningInWebWorker.d.ts +1 -1
  26. package/esm/typings/src/utils/random/$randomSeed.d.ts +2 -1
  27. package/esm/typings/src/utils/random/$randomToken.d.ts +13 -0
  28. package/esm/typings/src/wizzard/wizzard.d.ts +2 -3
  29. package/package.json +2 -2
  30. package/umd/index.umd.js +3 -3
  31. package/umd/index.umd.js.map +1 -1
  32. package/esm/typings/src/remote-server/socket-types/_common/PromptbookServer_Progress.d.ts +0 -10
  33. package/esm/typings/src/types/TaskProgress.d.ts +0 -43
@@ -17,5 +17,5 @@ import type { RemoteClientOptions } from '../remote-server/types/RemoteClientOpt
17
17
  */
18
18
  export declare function compilePipelineOnRemoteServer<TCustomOptions = undefined>(pipelineString: PipelineString, options: RemoteClientOptions<TCustomOptions>): Promise<PipelineJson>;
19
19
  /**
20
- * TODO: [🐚] Do not return Promise<PipelineJson> But PreparePipelineTask
20
+ * TODO: [🐚] Do not return `Promise<PipelineJson>` But `PreparationTask`
21
21
  */
@@ -0,0 +1,25 @@
1
+ import { ReadonlyDeep } from 'type-fest';
2
+ import type { ErrorJson } from '../errors/utils/ErrorJson';
3
+ /**
4
+ * @@@
5
+ *
6
+ * Note: [🚉] This is fully serializable as JSON
7
+ */
8
+ export type AbstractTaskResult = {
9
+ /**
10
+ * Whether the execution was successful, details are aviable in `executionReport`
11
+ */
12
+ readonly isSuccessful: boolean;
13
+ /**
14
+ * Errors that occured during the execution, details are aviable in `executionReport`
15
+ */
16
+ readonly errors: ReadonlyDeep<ReadonlyArray<ErrorJson>>;
17
+ /**
18
+ * Warnings that occured during the execution, details are aviable in `executionReport`
19
+ */
20
+ readonly warnings: ReadonlyDeep<ReadonlyArray<ErrorJson>>;
21
+ };
22
+ /**
23
+ * TODO: [🧠] Should this file be in /execution or /types folder?
24
+ * TODO: [🧠] Maybe constrain `ErrorJson` -> `ErrorJson & { name: 'PipelineExecutionError' | 'Error' }`
25
+ */
@@ -0,0 +1,71 @@
1
+ import type { Observable } from 'rxjs';
2
+ import { PartialDeep } from 'type-fest';
3
+ import type { string_SCREAMING_CASE } from '../utils/normalization/normalizeTo_SCREAMING_CASE';
4
+ import type { task_id } from '../types/typeAliases';
5
+ import type { AbstractTaskResult } from './AbstractTaskResult';
6
+ import type { PipelineExecutorResult } from './PipelineExecutorResult';
7
+ /**
8
+ * Options for creating a new task
9
+ */
10
+ type CreateTaskOptions<TTaskResult extends AbstractTaskResult> = {
11
+ /**
12
+ * The type of task to create
13
+ */
14
+ readonly taskType: AbstractTask<TTaskResult>['taskType'];
15
+ /**
16
+ * Callback that processes the task and updates the ongoing result
17
+ * @param ongoingResult The partial result of the task processing
18
+ * @returns The final task result
19
+ */
20
+ taskProcessCallback(updateOngoingResult: (newOngoingResult: PartialDeep<TTaskResult>) => void): Promise<TTaskResult>;
21
+ };
22
+ /**
23
+ * Helper to create a new task
24
+ *
25
+ * @private internal helper function
26
+ */
27
+ export declare function createTask<TTaskResult extends AbstractTaskResult>(options: CreateTaskOptions<TTaskResult>): AbstractTask<TTaskResult>;
28
+ /**
29
+ * Represents a task that executes a pipeline
30
+ */
31
+ export type ExecutionTask = AbstractTask<PipelineExecutorResult> & {
32
+ readonly taskType: 'EXECUTION';
33
+ readonly taskId: `execution-${task_id}`;
34
+ };
35
+ /**
36
+ * Represents a task that prepares a pipeline
37
+ * @deprecated TODO: [🐚] Currently unused - use
38
+ */
39
+ export type PreparationTask = AbstractTask<PipelineExecutorResult> & {
40
+ readonly taskType: 'PREPARATION';
41
+ readonly taskId: `preparation-${task_id}`;
42
+ };
43
+ /**
44
+ * Base interface for all task types
45
+ */
46
+ export type AbstractTask<TTaskResult extends AbstractTaskResult> = {
47
+ /**
48
+ * Type of the task
49
+ */
50
+ readonly taskType: string_SCREAMING_CASE;
51
+ /**
52
+ * Unique identifier for the task
53
+ */
54
+ readonly taskId: task_id;
55
+ /**
56
+ * Gets a promise that resolves with the task result
57
+ */
58
+ asPromise(options?: {
59
+ readonly isCrashedOnError?: boolean;
60
+ }): Promise<TTaskResult>;
61
+ /**
62
+ * Gets an observable stream of partial task results
63
+ */
64
+ asObservable(): Observable<PartialDeep<TTaskResult>>;
65
+ };
66
+ export type Task = ExecutionTask | PreparationTask;
67
+ export {};
68
+ /**
69
+ * TODO: Maybe allow to terminate the task and add getter `isFinished` or `status`
70
+ * TODO: [🐚] Split into more files and make `PrepareTask` & `RemoteTask` + split the function
71
+ */
@@ -1,7 +1,5 @@
1
- import type { Promisable } from 'type-fest';
2
- import type { TaskProgress } from '../types/TaskProgress';
3
1
  import type { InputParameters } from '../types/typeAliases';
4
- import type { PipelineExecutorResult } from './PipelineExecutorResult';
2
+ import type { ExecutionTask } from './ExecutionTask';
5
3
  /**
6
4
  * Executor is a simple async function that takes INPUT PARAMETERs and returns result parameters _(along with all intermediate parameters and INPUT PARAMETERs = it extends input object)_.
7
5
  * Executor is made by combining execution tools and pipeline collection.
@@ -11,9 +9,8 @@ import type { PipelineExecutorResult } from './PipelineExecutorResult';
11
9
  * @see https://github.com/webgptorg/promptbook#executor
12
10
  */
13
11
  export type PipelineExecutor = {
14
- (inputParameters: InputParameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<PipelineExecutorResult>;
12
+ (inputParameters: InputParameters): ExecutionTask;
15
13
  };
16
14
  /**
17
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
18
15
  * TODO: [🧠] Should this file be in /execution or /types folder?
19
16
  */
@@ -1,7 +1,7 @@
1
1
  import { ReadonlyDeep } from 'type-fest';
2
- import type { ErrorJson } from '../errors/utils/ErrorJson';
3
2
  import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
4
3
  import type { Parameters } from '../types/typeAliases';
4
+ import type { AbstractTaskResult } from './AbstractTaskResult';
5
5
  import type { ExecutionReportJson } from './execution-report/ExecutionReportJson';
6
6
  import type { PromptResultUsage } from './PromptResultUsage';
7
7
  /**
@@ -9,29 +9,17 @@ import type { PromptResultUsage } from './PromptResultUsage';
9
9
  *
10
10
  * Note: [🚉] This is fully serializable as JSON
11
11
  */
12
- export type PipelineExecutorResult = {
12
+ export type PipelineExecutorResult = AbstractTaskResult & {
13
13
  /**
14
14
  * Result parameters of the execution
15
15
  *
16
16
  * Note: If the execution was not successful, there are only some of the result parameters
17
17
  */
18
18
  readonly outputParameters: Readonly<Parameters>;
19
- /**
20
- * Whether the execution was successful, details are aviable in `executionReport`
21
- */
22
- readonly isSuccessful: boolean;
23
19
  /**
24
20
  * Added usage of whole execution, detailed usage is aviable in `executionReport`
25
21
  */
26
22
  readonly usage: ReadonlyDeep<PromptResultUsage>;
27
- /**
28
- * Errors that occured during the execution, details are aviable in `executionReport`
29
- */
30
- readonly errors: ReadonlyDeep<ReadonlyArray<ErrorJson>>;
31
- /**
32
- * Warnings that occured during the execution, details are aviable in `executionReport`
33
- */
34
- readonly warnings: ReadonlyDeep<ReadonlyArray<ErrorJson>>;
35
23
  /**
36
24
  * The report of the execution with all details
37
25
  */
@@ -46,5 +34,4 @@ export type PipelineExecutorResult = {
46
34
  };
47
35
  /**
48
36
  * TODO: [🧠] Should this file be in /execution or /types folder?
49
- * TODO: [🧠] Maybe constrain `ErrorJson` -> `ErrorJson & { name: 'PipelineExecutionError' | 'Error' }`
50
37
  */
@@ -1,5 +1,12 @@
1
1
  import type { string_url } from '../types/typeAliases';
2
2
  /**
3
- * Fetch function for fetching data from the internet used in scraping
3
+ * Fetch function used in Promptbook engine
4
+ *
5
+ * In most cases it is just native `fetch` function with a lightweight error handling wrapper
6
+ * But it can be replaced with any other fetch function, polyfill, custom implementation, security layer, etc.
7
+ *
8
+ * It is used in theese places:
9
+ * - Fetching knowledge sources
10
+ * - Callbacks from remote server ([👩🏾‍🤝‍🧑🏾] Not yet implemented)
4
11
  */
5
12
  export type PromptbookFetch = (url: string_url, init?: RequestInit) => Promise<Response>;
@@ -6,10 +6,9 @@ import type { PipelineExecutorResult } from './PipelineExecutorResult';
6
6
  *
7
7
  * @param executionResult - The partial result of the Promptbook execution
8
8
  * @throws {PipelineExecutionError} If the execution is not successful or if multiple errors occurred
9
- * @public exported from `@promptbook/core`
9
+ * @private internal helper function of `asPromise` method of `ExecutionTask`
10
10
  */
11
- export declare function assertsExecutionSuccessful(executionResult: Pick<PipelineExecutorResult, 'isSuccessful' | 'errors' | 'warnings'>): void;
11
+ export declare function assertsTaskSuccessful(executionResult: Pick<PipelineExecutorResult, 'isSuccessful' | 'errors' | 'warnings'>): void;
12
12
  /**
13
- * TODO: [🐚] This function should be removed OR changed OR be completely rewritten
14
13
  * TODO: [🧠] Can this return type be better typed than void
15
14
  */
@@ -8,6 +8,3 @@ import type { CreatePipelineExecutorOptions } from './00-CreatePipelineExecutorO
8
8
  * @public exported from `@promptbook/core`
9
9
  */
10
10
  export declare function createPipelineExecutor(options: CreatePipelineExecutorOptions): PipelineExecutor;
11
- /**
12
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
13
- */
@@ -1,6 +1,5 @@
1
- import type { Promisable, ReadonlyDeep } from 'type-fest';
1
+ import type { PartialDeep, Promisable, ReadonlyDeep } from 'type-fest';
2
2
  import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
3
- import type { TaskProgress } from '../../types/TaskProgress';
4
3
  import type { InputParameters } from '../../types/typeAliases';
5
4
  import type { PipelineExecutorResult } from '../PipelineExecutorResult';
6
5
  import type { CreatePipelineExecutorOptions } from './00-CreatePipelineExecutorOptions';
@@ -17,7 +16,7 @@ type ExecutePipelineOptions = Required<CreatePipelineExecutorOptions> & {
17
16
  /**
18
17
  * @@@
19
18
  */
20
- onProgress?(taskProgress: TaskProgress): Promisable<void>;
19
+ onProgress?(newOngoingResult: PartialDeep<PipelineExecutorResult>): Promisable<void>;
21
20
  /**
22
21
  * @@@
23
22
  */
@@ -44,6 +43,3 @@ type ExecutePipelineOptions = Required<CreatePipelineExecutorOptions> & {
44
43
  */
45
44
  export declare function executePipeline(options: ExecutePipelineOptions): Promise<PipelineExecutorResult>;
46
45
  export {};
47
- /**
48
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
49
- */
@@ -1,9 +1,9 @@
1
- import type { Promisable, ReadonlyDeep, WritableDeep } from 'type-fest';
1
+ import type { PartialDeep, Promisable, ReadonlyDeep, WritableDeep } from 'type-fest';
2
2
  import type { PipelineJson } from '../../pipeline/PipelineJson/PipelineJson';
3
3
  import type { TaskJson } from '../../pipeline/PipelineJson/TaskJson';
4
- import type { TaskProgress } from '../../types/TaskProgress';
5
4
  import type { Parameters } from '../../types/typeAliases';
6
5
  import type { ExecutionReportJson } from '../execution-report/ExecutionReportJson';
6
+ import type { PipelineExecutorResult } from '../PipelineExecutorResult';
7
7
  import type { CreatePipelineExecutorOptions } from './00-CreatePipelineExecutorOptions';
8
8
  /**
9
9
  * @@@
@@ -26,7 +26,7 @@ type executeSingleTaskOptions = Required<CreatePipelineExecutorOptions> & {
26
26
  /**
27
27
  * @@@
28
28
  */
29
- readonly onProgress: (taskProgress: TaskProgress) => Promisable<void>;
29
+ readonly onProgress: (newOngoingResult: PartialDeep<PipelineExecutorResult>) => Promisable<void>;
30
30
  /**
31
31
  * @@@
32
32
  */
@@ -46,6 +46,3 @@ export {};
46
46
  /**
47
47
  * TODO: [🤹‍♂️]
48
48
  */
49
- /**
50
- * TODO: [🐚] Change onProgress to object that represents the running execution, can be subscribed via RxJS to and also awaited
51
- */
@@ -13,5 +13,5 @@ import type { RemoteClientOptions } from '../remote-server/types/RemoteClientOpt
13
13
  */
14
14
  export declare function preparePipelineOnRemoteServer<TCustomOptions = undefined>(pipeline: PipelineJson, options: RemoteClientOptions<TCustomOptions>): Promise<PipelineJson>;
15
15
  /**
16
- * TODO: [🐚] Do not return Promise<PipelineJson> But PreparePipelineTask
16
+ * TODO: [🐚] Do not return `Promise<PipelineJson>` But `PreparationTask`
17
17
  */
@@ -11,6 +11,7 @@ import type { RemoteServerOptions } from './types/RemoteServerOptions';
11
11
  */
12
12
  export declare function startRemoteServer<TCustomOptions = undefined>(options: RemoteServerOptions<TCustomOptions>): IDestroyable;
13
13
  /**
14
+ * TODO: [👩🏾‍🤝‍🧑🏾] Allow to pass custom fetch function here - PromptbookFetch
14
15
  * TODO: Split this file into multiple functions - handler for each request
15
16
  * TODO: Maybe use `$exportJson`
16
17
  * TODO: [🧠][🛍] Maybe not `isAnonymous: boolean` BUT `mode: 'ANONYMOUS'|'COLLECTION'`
@@ -556,6 +556,7 @@ export type string_javascript_name = string;
556
556
  */
557
557
  export type string_postprocessing_function_name = string;
558
558
  export type id = string | number;
559
+ export type task_id = string;
559
560
  export type string_token = string;
560
561
  export type string_license_token = string_token;
561
562
  export type string_password = string;
@@ -588,6 +589,7 @@ export type number_tokens = number_integer & (number_positive | 0);
588
589
  export type number_positive = number;
589
590
  export type number_negative = number;
590
591
  export type number_integer = number;
592
+ export type number_port = number_positive & number_integer;
591
593
  /**
592
594
  * Semantic helper;
593
595
  * Percentage from 0 to 1 (100%) (and bellow and above)
@@ -7,5 +7,5 @@
7
7
  */
8
8
  export declare const $isRunningInBrowser: Function;
9
9
  /**
10
- * TODO: []
11
- */
10
+ * TODO: [🎺]
11
+ */
@@ -7,5 +7,5 @@
7
7
  */
8
8
  export declare const $isRunningInJest: Function;
9
9
  /**
10
- * TODO: []
11
- */
10
+ * TODO: [🎺]
11
+ */
@@ -7,5 +7,5 @@
7
7
  */
8
8
  export declare const $isRunningInNode: Function;
9
9
  /**
10
- * TODO: []
11
- */
10
+ * TODO: [🎺]
11
+ */
@@ -7,5 +7,5 @@
7
7
  */
8
8
  export declare const $isRunningInWebWorker: Function;
9
9
  /**
10
- * TODO: []
10
+ * TODO: [🎺]
11
11
  */
@@ -4,6 +4,7 @@ import type { number_seed } from '../../types/typeAliases';
4
4
  *
5
5
  * Note: `$` is used to indicate that this function is not a pure function - it is not deterministic
6
6
  * Warning: This function is NOT cryptographically secure (it uses Math.random internally)
7
- * @public exported from `@promptbook/utils`
7
+ *
8
+ * @private internal helper function
8
9
  */
9
10
  export declare function $randomSeed(): number_seed;
@@ -0,0 +1,13 @@
1
+ import type { string_token } from '../../types/typeAliases';
2
+ /**
3
+ * Generates random token
4
+ *
5
+ * Note: This function is cryptographically secure (it uses crypto.randomBytes internally)
6
+ *
7
+ * @private internal helper function
8
+ * @returns secure random token
9
+ */
10
+ export declare function $randomToken(randomness: number): string_token;
11
+ /**
12
+ * TODO: Maybe use nanoid instead https://github.com/ai/nanoid
13
+ */
@@ -1,9 +1,7 @@
1
- import { Promisable } from 'type-fest';
2
1
  import type { ExecutionTools } from '../execution/ExecutionTools';
3
2
  import type { PipelineExecutorResult } from '../execution/PipelineExecutorResult';
4
3
  import type { PipelineJson } from '../pipeline/PipelineJson/PipelineJson';
5
4
  import type { PipelineString } from '../pipeline/PipelineString';
6
- import type { TaskProgress } from '../types/TaskProgress';
7
5
  import type { InputParameters } from '../types/typeAliases';
8
6
  import type { string_filename } from '../types/typeAliases';
9
7
  import type { string_parameter_value } from '../types/typeAliases';
@@ -28,7 +26,7 @@ declare class Wizzard {
28
26
  *
29
27
  * Note: This works simmilar to the `ptbk run` command
30
28
  */
31
- execute(book: string_pipeline_url | string_filename | PipelineString, inputParameters: InputParameters, onProgress?: (taskProgress: TaskProgress) => Promisable<void>): Promise<{
29
+ execute(book: string_pipeline_url | string_filename | PipelineString, inputParameters: InputParameters): Promise<{
32
30
  /**
33
31
  * Simple result of the execution
34
32
  */
@@ -65,5 +63,6 @@ declare class Wizzard {
65
63
  export declare const wizzard: Wizzard;
66
64
  export {};
67
65
  /**
66
+ * TODO: [🧠] Maybe some way how to handle the progress and streaming?
68
67
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
69
68
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/openai",
3
- "version": "0.84.0",
3
+ "version": "0.85.0-0",
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/openai.index.d.ts",
49
49
  "peerDependencies": {
50
- "@promptbook/core": "0.84.0"
50
+ "@promptbook/core": "0.85.0-0"
51
51
  },
52
52
  "dependencies": {
53
53
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -24,7 +24,7 @@
24
24
  * @generated
25
25
  * @see https://github.com/webgptorg/promptbook
26
26
  */
27
- var PROMPTBOOK_ENGINE_VERSION = '0.84.0-21';
27
+ var PROMPTBOOK_ENGINE_VERSION = '0.84.0';
28
28
  /**
29
29
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
30
30
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -158,7 +158,7 @@
158
158
  */
159
159
  var $isRunningInBrowser = new Function("\n try {\n return this === window;\n } catch (e) {\n return false;\n }\n");
160
160
  /**
161
- * TODO: []
161
+ * TODO: [🎺]
162
162
  */
163
163
 
164
164
  /**
@@ -170,7 +170,7 @@
170
170
  */
171
171
  var $isRunningInWebWorker = new Function("\n try {\n if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {\n return true;\n } else {\n return false;\n }\n } catch (e) {\n return false;\n }\n");
172
172
  /**
173
- * TODO: []
173
+ * TODO: [🎺]
174
174
  */
175
175
 
176
176
  /**