@promptbook/markdown-utils 0.89.0-8 → 0.89.0-9

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 (25) hide show
  1. package/esm/index.es.js +27 -6
  2. package/esm/index.es.js.map +1 -1
  3. package/esm/typings/src/_packages/core.index.d.ts +4 -0
  4. package/esm/typings/src/_packages/remote-client.index.d.ts +6 -6
  5. package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
  6. package/esm/typings/src/_packages/types.index.d.ts +10 -18
  7. package/esm/typings/src/errors/0-index.d.ts +3 -0
  8. package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
  9. package/esm/typings/src/llm-providers/_common/register/$provideEnvFilepath.d.ts +12 -0
  10. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
  11. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
  12. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +5 -3
  13. package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
  14. package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
  15. package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
  16. package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
  17. package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
  18. package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +2 -2
  19. package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +43 -30
  20. package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
  21. package/package.json +1 -1
  22. package/umd/index.umd.js +27 -6
  23. package/umd/index.umd.js.map +1 -1
  24. package/esm/typings/src/playground/BrjappConnector.d.ts +0 -67
  25. package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
@@ -60,6 +60,7 @@ import { ParseError } from '../errors/ParseError';
60
60
  import { PipelineExecutionError } from '../errors/PipelineExecutionError';
61
61
  import { PipelineLogicError } from '../errors/PipelineLogicError';
62
62
  import { PipelineUrlError } from '../errors/PipelineUrlError';
63
+ import { PromptbookFetchError } from '../errors/PromptbookFetchError';
63
64
  import { UnexpectedError } from '../errors/UnexpectedError';
64
65
  import { createPipelineExecutor } from '../execution/createPipelineExecutor/00-createPipelineExecutor';
65
66
  import { embeddingVectorToString } from '../execution/embeddingVectorToString';
@@ -119,6 +120,7 @@ import { prepareKnowledgePieces } from '../scrapers/_common/prepareKnowledgePiec
119
120
  import { $scrapersMetadataRegister } from '../scrapers/_common/register/$scrapersMetadataRegister';
120
121
  import { $scrapersRegister } from '../scrapers/_common/register/$scrapersRegister';
121
122
  import { makeKnowledgeSourceHandler } from '../scrapers/_common/utils/makeKnowledgeSourceHandler';
123
+ import { promptbookFetch } from '../scrapers/_common/utils/promptbookFetch';
122
124
  import { _LegacyDocumentScraperMetadataRegistration } from '../scrapers/document-legacy/register-metadata';
123
125
  import { _DocumentScraperMetadataRegistration } from '../scrapers/document/register-metadata';
124
126
  import { _MarkdownScraperMetadataRegistration } from '../scrapers/markdown/register-metadata';
@@ -194,6 +196,7 @@ export { ParseError };
194
196
  export { PipelineExecutionError };
195
197
  export { PipelineLogicError };
196
198
  export { PipelineUrlError };
199
+ export { PromptbookFetchError };
197
200
  export { UnexpectedError };
198
201
  export { createPipelineExecutor };
199
202
  export { embeddingVectorToString };
@@ -253,6 +256,7 @@ export { prepareKnowledgePieces };
253
256
  export { $scrapersMetadataRegister };
254
257
  export { $scrapersRegister };
255
258
  export { makeKnowledgeSourceHandler };
259
+ export { promptbookFetch };
256
260
  export { _LegacyDocumentScraperMetadataRegistration };
257
261
  export { _DocumentScraperMetadataRegistration };
258
262
  export { _MarkdownScraperMetadataRegistration };
@@ -2,15 +2,15 @@ import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
2
2
  import { compilePipelineOnRemoteServer } from '../conversion/compilePipelineOnRemoteServer';
3
3
  import { RemoteLlmExecutionTools } from '../llm-providers/remote/RemoteLlmExecutionTools';
4
4
  import { preparePipelineOnRemoteServer } from '../prepare/preparePipelineOnRemoteServer';
5
- import type { PromptbookServer_Identification } from '../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
6
- import type { PromptbookServer_ApplicationIdentification } from '../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
7
- import type { PromptbookServer_AnonymousIdentification } from '../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
5
+ import type { Identification } from '../remote-server/socket-types/_subtypes/Identification';
6
+ import type { ApplicationModeIdentification } from '../remote-server/socket-types/_subtypes/Identification';
7
+ import type { AnonymousModeIdentification } from '../remote-server/socket-types/_subtypes/Identification';
8
8
  import type { RemoteClientOptions } from '../remote-server/types/RemoteClientOptions';
9
9
  export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
10
10
  export { compilePipelineOnRemoteServer };
11
11
  export { RemoteLlmExecutionTools };
12
12
  export { preparePipelineOnRemoteServer };
13
- export type { PromptbookServer_Identification };
14
- export type { PromptbookServer_ApplicationIdentification };
15
- export type { PromptbookServer_AnonymousIdentification };
13
+ export type { Identification };
14
+ export type { ApplicationModeIdentification };
15
+ export type { AnonymousModeIdentification };
16
16
  export type { RemoteClientOptions };
@@ -1,12 +1,12 @@
1
1
  import { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION } from '../version';
2
- import type { PromptbookServer_Identification } from '../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
3
- import type { PromptbookServer_ApplicationIdentification } from '../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
4
- import type { PromptbookServer_AnonymousIdentification } from '../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
2
+ import type { Identification } from '../remote-server/socket-types/_subtypes/Identification';
3
+ import type { ApplicationModeIdentification } from '../remote-server/socket-types/_subtypes/Identification';
4
+ import type { AnonymousModeIdentification } from '../remote-server/socket-types/_subtypes/Identification';
5
5
  import { startRemoteServer } from '../remote-server/startRemoteServer';
6
6
  import type { RemoteServerOptions } from '../remote-server/types/RemoteServerOptions';
7
7
  export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION };
8
- export type { PromptbookServer_Identification };
9
- export type { PromptbookServer_ApplicationIdentification };
10
- export type { PromptbookServer_AnonymousIdentification };
8
+ export type { Identification };
9
+ export type { ApplicationModeIdentification };
10
+ export type { AnonymousModeIdentification };
11
11
  export { startRemoteServer };
12
12
  export type { RemoteServerOptions };
@@ -106,22 +106,18 @@ import type { ScriptTaskJson } from '../pipeline/PipelineJson/ScriptTaskJson';
106
106
  import type { SimpleTaskJson } from '../pipeline/PipelineJson/SimpleTaskJson';
107
107
  import type { TaskJson } from '../pipeline/PipelineJson/TaskJson';
108
108
  import type { PipelineString } from '../pipeline/PipelineString';
109
- import type { paths } from '../playground/brjapp-api-schema';
110
- import type { webhooks } from '../playground/brjapp-api-schema';
111
- import type { components } from '../playground/brjapp-api-schema';
112
- import type { $defs } from '../playground/brjapp-api-schema';
113
- import type { operations } from '../playground/brjapp-api-schema';
114
109
  import type { PrepareAndScrapeOptions } from '../prepare/PrepareAndScrapeOptions';
115
110
  import type { RemoteServer } from '../remote-server/RemoteServer';
116
- import type { PromptbookServer_Identification } from '../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
117
- import type { PromptbookServer_ApplicationIdentification } from '../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
118
- import type { PromptbookServer_AnonymousIdentification } from '../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
111
+ import type { Identification } from '../remote-server/socket-types/_subtypes/Identification';
112
+ import type { ApplicationModeIdentification } from '../remote-server/socket-types/_subtypes/Identification';
113
+ import type { AnonymousModeIdentification } from '../remote-server/socket-types/_subtypes/Identification';
119
114
  import type { RemoteClientOptions } from '../remote-server/types/RemoteClientOptions';
120
115
  import type { RemoteServerOptions } from '../remote-server/types/RemoteServerOptions';
121
116
  import type { AnonymousRemoteServerOptions } from '../remote-server/types/RemoteServerOptions';
122
117
  import type { ApplicationRemoteServerOptions } from '../remote-server/types/RemoteServerOptions';
123
118
  import type { ApplicationRemoteServerClientOptions } from '../remote-server/types/RemoteServerOptions';
124
- import type { ApplicationRemoteServerOptionsLoginResponse } from '../remote-server/types/RemoteServerOptions';
119
+ import type { LoginRequest } from '../remote-server/types/RemoteServerOptions';
120
+ import type { LoginResponse } from '../remote-server/types/RemoteServerOptions';
125
121
  import type { Converter } from '../scrapers/_common/Converter';
126
122
  import type { ScraperAndConverterMetadata } from '../scrapers/_common/register/ScraperAndConverterMetadata';
127
123
  import type { ScraperConstructor } from '../scrapers/_common/register/ScraperConstructor';
@@ -397,22 +393,18 @@ export type { ScriptTaskJson };
397
393
  export type { SimpleTaskJson };
398
394
  export type { TaskJson };
399
395
  export type { PipelineString };
400
- export type { paths };
401
- export type { webhooks };
402
- export type { components };
403
- export type { $defs };
404
- export type { operations };
405
396
  export type { PrepareAndScrapeOptions };
406
397
  export type { RemoteServer };
407
- export type { PromptbookServer_Identification };
408
- export type { PromptbookServer_ApplicationIdentification };
409
- export type { PromptbookServer_AnonymousIdentification };
398
+ export type { Identification };
399
+ export type { ApplicationModeIdentification };
400
+ export type { AnonymousModeIdentification };
410
401
  export type { RemoteClientOptions };
411
402
  export type { RemoteServerOptions };
412
403
  export type { AnonymousRemoteServerOptions };
413
404
  export type { ApplicationRemoteServerOptions };
414
405
  export type { ApplicationRemoteServerClientOptions };
415
- export type { ApplicationRemoteServerOptionsLoginResponse };
406
+ export type { LoginRequest };
407
+ export type { LoginResponse };
416
408
  export type { Converter };
417
409
  export type { ScraperAndConverterMetadata };
418
410
  export type { ScraperConstructor };
@@ -13,6 +13,7 @@ import { ParseError } from './ParseError';
13
13
  import { PipelineExecutionError } from './PipelineExecutionError';
14
14
  import { PipelineLogicError } from './PipelineLogicError';
15
15
  import { PipelineUrlError } from './PipelineUrlError';
16
+ import { PromptbookFetchError } from './PromptbookFetchError';
16
17
  import { UnexpectedError } from './UnexpectedError';
17
18
  /**
18
19
  * Index of all custom errors
@@ -51,6 +52,7 @@ export declare const COMMON_JAVASCRIPT_ERRORS: {
51
52
  readonly URIError: URIErrorConstructor;
52
53
  readonly AggregateError: AggregateErrorConstructor;
53
54
  readonly AuthenticationError: typeof AuthenticationError;
55
+ readonly PromptbookFetchError: typeof PromptbookFetchError;
54
56
  };
55
57
  /**
56
58
  * Index of all errors
@@ -67,6 +69,7 @@ export declare const ALL_ERRORS: {
67
69
  readonly URIError: URIErrorConstructor;
68
70
  readonly AggregateError: AggregateErrorConstructor;
69
71
  readonly AuthenticationError: typeof AuthenticationError;
72
+ readonly PromptbookFetchError: typeof PromptbookFetchError;
70
73
  readonly AbstractFormatError: typeof AbstractFormatError;
71
74
  readonly CsvFormatError: typeof CsvFormatError;
72
75
  readonly CollectionError: typeof CollectionError;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Error thrown when a fetch request fails
3
+ *
4
+ * @public exported from `@promptbook/core`
5
+ */
6
+ export declare class PromptbookFetchError extends Error {
7
+ readonly name = "PromptbookFetchError";
8
+ constructor(message: string);
9
+ }
@@ -0,0 +1,12 @@
1
+ import type { string_filename } from '../../../types/typeAliases';
2
+ /**
3
+ * Provides the path to the `.env` file
4
+ *
5
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
6
+ *
7
+ * @private within the repository - for CLI utils
8
+ */
9
+ export declare function $provideEnvFilepath(): Promise<string_filename | null>;
10
+ /**
11
+ * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
12
+ */
@@ -3,6 +3,7 @@ import type { LlmToolsConfiguration } from './LlmToolsConfiguration';
3
3
  * @@@
4
4
  *
5
5
  * @@@ .env
6
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
6
7
  *
7
8
  * It looks for environment variables:
8
9
  * - `process.env.OPENAI_API_KEY`
@@ -14,12 +15,5 @@ import type { LlmToolsConfiguration } from './LlmToolsConfiguration';
14
15
  */
15
16
  export declare function $provideLlmToolsConfigurationFromEnv(): Promise<LlmToolsConfiguration>;
16
17
  /**
17
- * TODO: [🧠][🪁] Maybe do allow to do auto-install if package not registered and not found
18
- * TODO: Add Azure OpenAI
19
- * TODO: [🧠][🍛]
20
- * TODO: [🧠] Is there some meaningfull way how to test this util
21
18
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
22
- * TODO: [👷‍♂️] @@@ Manual about construction of llmTools
23
- * TODO: This should be maybe not under `_common` but under `utils`
24
- * TODO: [🧠][⚛] Maybe pass env as argument
25
- * TODO: [®] DRY Register logic */
19
+ */
@@ -12,6 +12,8 @@ type GetLlmToolsForTestingAndScriptsAndPlaygroundOptions = CreateLlmToolsFromCon
12
12
  /**
13
13
  * Returns LLM tools for testing purposes
14
14
  *
15
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
16
+ *
15
17
  * @private within the repository - JUST FOR TESTS, SCRIPTS AND PLAYGROUND
16
18
  */
17
19
  export declare function $provideLlmToolsForTestingAndScriptsAndPlayground(options?: GetLlmToolsForTestingAndScriptsAndPlaygroundOptions): Promise<LlmExecutionToolsWithTotalUsage>;
@@ -1,8 +1,8 @@
1
1
  import { Promisable } from 'type-fest';
2
- import type { PromptbookServer_Identification } from '../../../remote-server/socket-types/_subtypes/PromptbookServer_Identification';
3
- import type { really_any } from '../../../utils/organization/really_any';
2
+ import type { Identification } from '../../../remote-server/socket-types/_subtypes/Identification';
4
3
  import type { string_app_id } from '../../../types/typeAliases';
5
4
  import type { string_url } from '../../../types/typeAliases';
5
+ import type { really_any } from '../../../utils/organization/really_any';
6
6
  import type { CacheLlmToolsOptions } from '../utils/cache/CacheLlmToolsOptions';
7
7
  import type { LlmExecutionToolsWithTotalUsage } from '../utils/count-total-usage/LlmExecutionToolsWithTotalUsage';
8
8
  type ProvideLlmToolsForWizzardOrCliOptions = Pick<CacheLlmToolsOptions, 'isCacheReloaded'> & ({
@@ -30,11 +30,13 @@ type ProvideLlmToolsForWizzardOrCliOptions = Pick<CacheLlmToolsOptions, 'isCache
30
30
  /**
31
31
  *
32
32
  */
33
- loginPrompt(): Promisable<PromptbookServer_Identification<really_any>>;
33
+ loginPrompt(): Promisable<Identification<really_any>>;
34
34
  });
35
35
  /**
36
36
  * Returns LLM tools for CLI
37
37
  *
38
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file and also writes this .env file
39
+ *
38
40
  * @private within the repository - for CLI utils
39
41
  */
40
42
  export declare function $provideLlmToolsForWizzardOrCli(options?: ProvideLlmToolsForWizzardOrCliOptions): Promise<LlmExecutionToolsWithTotalUsage>;
@@ -6,6 +6,7 @@ import type { CreateLlmToolsFromConfigurationOptions } from './createLlmToolsFro
6
6
  * Note: This function is not cached, every call creates new instance of `MultipleLlmExecutionTools`
7
7
  *
8
8
  * @@@ .env
9
+ * Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access .env file
9
10
  *
10
11
  * It looks for environment variables:
11
12
  * - `process.env.OPENAI_API_KEY`
@@ -7,14 +7,14 @@ import type { ApplicationRemoteServerClientOptions } from '../../types/RemoteSer
7
7
  * @public exported from `@promptbook/remote-server`
8
8
  * @public exported from `@promptbook/remote-client`
9
9
  */
10
- export type PromptbookServer_Identification<TCustomOptions> = PromptbookServer_ApplicationIdentification<TCustomOptions> | PromptbookServer_AnonymousIdentification;
10
+ export type Identification<TCustomOptions> = ApplicationModeIdentification<TCustomOptions> | AnonymousModeIdentification;
11
11
  /**
12
12
  * Application mode is situation when you run known and well-defined books with your own api keys
13
13
  *
14
14
  * @public exported from `@promptbook/remote-server`
15
15
  * @public exported from `@promptbook/remote-client`
16
16
  */
17
- export type PromptbookServer_ApplicationIdentification<TCustomOptions> = ApplicationRemoteServerClientOptions<TCustomOptions> & {
17
+ export type ApplicationModeIdentification<TCustomOptions> = ApplicationRemoteServerClientOptions<TCustomOptions> & {
18
18
  /**
19
19
  * Application mode
20
20
  */
@@ -29,7 +29,7 @@ export type PromptbookServer_ApplicationIdentification<TCustomOptions> = Applica
29
29
  * @public exported from `@promptbook/remote-server`
30
30
  * @public exported from `@promptbook/remote-client`
31
31
  */
32
- export type PromptbookServer_AnonymousIdentification = {
32
+ export type AnonymousModeIdentification = {
33
33
  /**
34
34
  * Anonymous mode
35
35
  */
@@ -1,4 +1,4 @@
1
- import type { PromptbookServer_Identification } from '../_subtypes/PromptbookServer_Identification';
1
+ import type { Identification } from '../_subtypes/Identification';
2
2
  /**
3
3
  * List models available in the server
4
4
  *
@@ -10,7 +10,7 @@ export type PromptbookServer_ListModels_Request<TCustomOptions> = {
10
10
  /**
11
11
  * Identifier of the end user or application
12
12
  */
13
- readonly identification: PromptbookServer_Identification<TCustomOptions>;
13
+ readonly identification: Identification<TCustomOptions>;
14
14
  };
15
15
  /**
16
16
  * TODO: [🧠] Listing models inanonymous mode does not make sence - keeping only to preserve consistency
@@ -1,5 +1,5 @@
1
1
  import type { PipelineJson } from '../../../pipeline/PipelineJson/PipelineJson';
2
- import type { PromptbookServer_Identification } from '../_subtypes/PromptbookServer_Identification';
2
+ import type { Identification } from '../_subtypes/Identification';
3
3
  /**
4
4
  * This is a request from client to server to prepare a pipeline
5
5
  *
@@ -9,7 +9,7 @@ export type PromptbookServer_PreparePipeline_Request<TCustomOptions> = {
9
9
  /**
10
10
  * Identifier of the end user or application
11
11
  */
12
- readonly identification: PromptbookServer_Identification<TCustomOptions>;
12
+ readonly identification: Identification<TCustomOptions>;
13
13
  /**
14
14
  * The Pipeline to prepare
15
15
  */
@@ -1,5 +1,5 @@
1
1
  import type { Prompt } from '../../../types/Prompt';
2
- import type { PromptbookServer_Identification } from '../_subtypes/PromptbookServer_Identification';
2
+ import type { Identification } from '../_subtypes/Identification';
3
3
  /**
4
4
  * This is a request from client to server to execute a prompt
5
5
  *
@@ -9,7 +9,7 @@ export type PromptbookServer_Prompt_Request<TCustomOptions> = {
9
9
  /**
10
10
  * Identifier of the end user or application
11
11
  */
12
- readonly identification: PromptbookServer_Identification<TCustomOptions>;
12
+ readonly identification: Identification<TCustomOptions>;
13
13
  /**
14
14
  * The Prompt to execute
15
15
  */
@@ -1,6 +1,6 @@
1
1
  import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
2
2
  import type { string_base_url } from '../../types/typeAliases';
3
- import type { PromptbookServer_Identification } from '../socket-types/_subtypes/PromptbookServer_Identification';
3
+ import type { Identification } from '../socket-types/_subtypes/Identification';
4
4
  /**
5
5
  * Options for `RemoteLlmExecutionTools`
6
6
  *
@@ -15,7 +15,7 @@ export type RemoteClientOptions<TCustomOptions> = CommonToolsOptions & {
15
15
  /**
16
16
  * Identification of client for Socket.io remote server
17
17
  */
18
- readonly identification: PromptbookServer_Identification<TCustomOptions>;
18
+ readonly identification: Identification<TCustomOptions>;
19
19
  };
20
20
  /**
21
21
  * TODO: Pass more options from Socket.io to `RemoteClientOptions` (like `transports`)
@@ -9,7 +9,7 @@ import type { string_email } from '../../types/typeAliases';
9
9
  import type { string_password } from '../../types/typeAliases';
10
10
  import type { string_uri } from '../../types/typeAliases';
11
11
  import type { string_user_id } from '../../types/typeAliases';
12
- import type { PromptbookServer_Identification } from '../socket-types/_subtypes/PromptbookServer_Identification';
12
+ import type { Identification } from '../socket-types/_subtypes/Identification';
13
13
  /**
14
14
  * @@@
15
15
  *
@@ -70,32 +70,7 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
70
70
  * Note: In most cases DO NOT THROW `AuthenticationError` but return `isSuccess: false` with message
71
71
  * @throws `AuthenticationError` if the user is not allowed to login for example because of invalid credentials
72
72
  */
73
- login(credentials: {
74
- /**
75
- * Identifier of the application you are using
76
- *
77
- * Note: This is usefull when you use Promptbook remote server for multiple apps/frontends, if its used just for single app, use here just "app" or "your-app-name"
78
- */
79
- readonly appId: string_app_id | null;
80
- /**
81
- * Username (for example email) of the user
82
- */
83
- readonly username: string_email | string;
84
- /**
85
- * Password of the user
86
- */
87
- readonly password: string_password;
88
- /**
89
- * Request object from express if you want to access some request data for example headers, IP address, etc.
90
- */
91
- readonly rawRequest: Request;
92
- /**
93
- * Response object from express if you want to add some custom headers.
94
- *
95
- * Note: It is not recommended to use this object to send body of the response because it can confuse the client
96
- */
97
- readonly rawResponse: Response;
98
- }): Promise<ApplicationRemoteServerOptionsLoginResponse<TCustomOptions>>;
73
+ login(loginRequest: LoginRequest): Promise<LoginResponse<TCustomOptions>>;
99
74
  /**
100
75
  * Creates llm execution tools for each client
101
76
  */
@@ -127,17 +102,55 @@ export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
127
102
  */
128
103
  readonly customOptions?: TCustomOptions;
129
104
  };
130
- export type ApplicationRemoteServerOptionsLoginResponse<TCustomOptions> = {
105
+ /**
106
+ * Login request for the application mode
107
+ */
108
+ export type LoginRequest = {
109
+ /**
110
+ * Identifier of the application you are using
111
+ *
112
+ * Note: This is usefull when you use Promptbook remote server for multiple apps/frontends, if its used just for single app, use here just "app" or "your-app-name"
113
+ */
114
+ readonly appId: string_app_id | null;
115
+ /**
116
+ * Username (for example email) of the user
117
+ */
118
+ readonly username: string_email | string;
119
+ /**
120
+ * Password of the user
121
+ */
122
+ readonly password: string_password;
123
+ /**
124
+ * Request object from express if you want to access some request data for example headers, IP address, etc.
125
+ */
126
+ readonly rawRequest: Request;
127
+ /**
128
+ * Response object from express if you want to add some custom headers.
129
+ *
130
+ * Note: It is not recommended to use this object to send body of the response because it can confuse the client
131
+ */
132
+ readonly rawResponse: Response;
133
+ };
134
+ /**
135
+ * Login response for the application mode
136
+ */
137
+ export type LoginResponse<TCustomOptions> = {
131
138
  /**
132
139
  * Was the login successful
133
140
  */
134
141
  readonly isSuccess: boolean;
135
142
  /**
136
- *
143
+ * Message to display to the user, this message is always displayed
137
144
  */
138
145
  readonly message?: string;
146
+ /**
147
+ * Optional error if the login was not successful
148
+ */
139
149
  readonly error?: AuthenticationError;
140
- readonly identification?: PromptbookServer_Identification<TCustomOptions>;
150
+ /**
151
+ * Identification of the user to be used in the future requests
152
+ */
153
+ readonly identification?: Identification<TCustomOptions>;
141
154
  };
142
155
  /**
143
156
  * TODO: Constrain anonymous mode for specific models / providers
@@ -2,9 +2,9 @@ import type { PromptbookFetch } from '../../../execution/PromptbookFetch';
2
2
  /**
3
3
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
4
4
  *
5
- * @private as default `fetch` function used in Promptbook scrapers
5
+ * @public exported from `@promptbook/core`
6
6
  */
7
- export declare const scraperFetch: PromptbookFetch;
7
+ export declare const promptbookFetch: PromptbookFetch;
8
8
  /**
9
9
  * TODO: [🧠] Maybe rename because it is not used only for scrapers but also in `$getCompiledBook`
10
10
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/markdown-utils",
3
- "version": "0.89.0-8",
3
+ "version": "0.89.0-9",
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,
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-8';
28
+ const PROMPTBOOK_ENGINE_VERSION = '0.89.0-9';
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
@@ -1912,6 +1912,19 @@
1912
1912
  }
1913
1913
  }
1914
1914
 
1915
+ /**
1916
+ * Error thrown when a fetch request fails
1917
+ *
1918
+ * @public exported from `@promptbook/core`
1919
+ */
1920
+ class PromptbookFetchError extends Error {
1921
+ constructor(message) {
1922
+ super(message);
1923
+ this.name = 'PromptbookFetchError';
1924
+ Object.setPrototypeOf(this, PromptbookFetchError.prototype);
1925
+ }
1926
+ }
1927
+
1915
1928
  /**
1916
1929
  * Index of all custom errors
1917
1930
  *
@@ -1950,6 +1963,7 @@
1950
1963
  URIError,
1951
1964
  AggregateError,
1952
1965
  AuthenticationError,
1966
+ PromptbookFetchError,
1953
1967
  /*
1954
1968
  Note: Not widely supported
1955
1969
  > InternalError,
@@ -3315,17 +3329,24 @@
3315
3329
  /**
3316
3330
  * The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
3317
3331
  *
3318
- * @private as default `fetch` function used in Promptbook scrapers
3332
+ * @public exported from `@promptbook/core`
3319
3333
  */
3320
- const scraperFetch = async (url, init) => {
3334
+ const promptbookFetch = async (urlOrRequest, init) => {
3321
3335
  try {
3322
- return await fetch(url, init);
3336
+ return await fetch(urlOrRequest, init);
3323
3337
  }
3324
3338
  catch (error) {
3325
3339
  if (!(error instanceof Error)) {
3326
3340
  throw error;
3327
3341
  }
3328
- throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
3342
+ let url;
3343
+ if (typeof urlOrRequest === 'string') {
3344
+ url = urlOrRequest;
3345
+ }
3346
+ else if (urlOrRequest instanceof Request) {
3347
+ url = urlOrRequest.url;
3348
+ }
3349
+ throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
3329
3350
  Can not fetch "${url}"
3330
3351
 
3331
3352
  Fetch error:
@@ -3346,7 +3367,7 @@
3346
3367
  async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
3347
3368
  // console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
3348
3369
  var _a;
3349
- const { fetch = scraperFetch } = tools;
3370
+ const { fetch = promptbookFetch } = tools;
3350
3371
  const { knowledgeSourceContent } = knowledgeSource;
3351
3372
  let { name } = knowledgeSource;
3352
3373
  const { rootDirname = null,