@promptbook/markdown-utils 0.89.0-7 → 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 -16
  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 +63 -21
  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,21 +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';
119
+ import type { LoginRequest } from '../remote-server/types/RemoteServerOptions';
120
+ import type { LoginResponse } from '../remote-server/types/RemoteServerOptions';
124
121
  import type { Converter } from '../scrapers/_common/Converter';
125
122
  import type { ScraperAndConverterMetadata } from '../scrapers/_common/register/ScraperAndConverterMetadata';
126
123
  import type { ScraperConstructor } from '../scrapers/_common/register/ScraperConstructor';
@@ -396,21 +393,18 @@ export type { ScriptTaskJson };
396
393
  export type { SimpleTaskJson };
397
394
  export type { TaskJson };
398
395
  export type { PipelineString };
399
- export type { paths };
400
- export type { webhooks };
401
- export type { components };
402
- export type { $defs };
403
- export type { operations };
404
396
  export type { PrepareAndScrapeOptions };
405
397
  export type { RemoteServer };
406
- export type { PromptbookServer_Identification };
407
- export type { PromptbookServer_ApplicationIdentification };
408
- export type { PromptbookServer_AnonymousIdentification };
398
+ export type { Identification };
399
+ export type { ApplicationModeIdentification };
400
+ export type { AnonymousModeIdentification };
409
401
  export type { RemoteClientOptions };
410
402
  export type { RemoteServerOptions };
411
403
  export type { AnonymousRemoteServerOptions };
412
404
  export type { ApplicationRemoteServerOptions };
413
405
  export type { ApplicationRemoteServerClientOptions };
406
+ export type { LoginRequest };
407
+ export type { LoginResponse };
414
408
  export type { Converter };
415
409
  export type { ScraperAndConverterMetadata };
416
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`)
@@ -1,5 +1,7 @@
1
+ import type { Request, Response } from 'express';
1
2
  import type { Promisable } from 'type-fest';
2
3
  import type { PipelineCollection } from '../../collection/PipelineCollection';
4
+ import { AuthenticationError } from '../../errors/AuthenticationError';
3
5
  import type { CommonToolsOptions } from '../../execution/CommonToolsOptions';
4
6
  import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
5
7
  import type { string_app_id } from '../../types/typeAliases';
@@ -7,7 +9,7 @@ import type { string_email } from '../../types/typeAliases';
7
9
  import type { string_password } from '../../types/typeAliases';
8
10
  import type { string_uri } from '../../types/typeAliases';
9
11
  import type { string_user_id } from '../../types/typeAliases';
10
- import type { PromptbookServer_Identification } from '../socket-types/_subtypes/PromptbookServer_Identification';
12
+ import type { Identification } from '../socket-types/_subtypes/Identification';
11
13
  /**
12
14
  * @@@
13
15
  *
@@ -35,7 +37,11 @@ export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
35
37
  * @example '/api/promptbook/'
36
38
  */
37
39
  readonly rootPath?: string_uri;
38
- } & (AnonymousRemoteServerOptions | ApplicationRemoteServerOptions<TCustomOptions> | (AnonymousRemoteServerOptions & ApplicationRemoteServerOptions<TCustomOptions>));
40
+ } & ((AnonymousRemoteServerOptions & {
41
+ readonly isApplicationModeAllowed?: false;
42
+ }) | ({
43
+ readonly isAnonymousModeAllowed?: false;
44
+ } & ApplicationRemoteServerOptions<TCustomOptions>) | (AnonymousRemoteServerOptions & ApplicationRemoteServerOptions<TCustomOptions>));
39
45
  export type AnonymousRemoteServerOptions = {
40
46
  /**
41
47
  * Enable anonymous mode
@@ -55,30 +61,16 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
55
61
  readonly collection: PipelineCollection;
56
62
  /**
57
63
  * User tries to login to the server, this function will be called verify the user and return the identification or throw an error
58
- *
64
+ * This can be also doubled as a function to register the user
59
65
  *
60
66
  * Note: In most cases, you will return `PromptbookServer_ApplicationIdentification`
61
67
  * `PromptbookServer_AnonymousIdentification` is useful only in scenarios when user stores its own api keys on the application server and
62
68
  * server acts only as a api key provider
63
69
  *
64
- * @throws `AuthenticationError` if the user is not allowed to login for example because of invalid credentials
65
- */
66
- login(credentials: {
67
- /**
68
- * Identifier of the application you are using
69
- *
70
- * 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"
71
- */
72
- readonly appId: string_app_id | null;
73
- /**
74
- * Username (for example email) of the user
75
- */
76
- readonly username: string_email | string;
77
- /**
78
- * Password of the user
79
- */
80
- readonly password: string_password;
81
- }): Promise<PromptbookServer_Identification<TCustomOptions>>;
70
+ * Note: In most cases DO NOT THROW `AuthenticationError` but return `isSuccess: false` with message
71
+ * @throws `AuthenticationError` if the user is not allowed to login for example because of invalid credentials
72
+ */
73
+ login(loginRequest: LoginRequest): Promise<LoginResponse<TCustomOptions>>;
82
74
  /**
83
75
  * Creates llm execution tools for each client
84
76
  */
@@ -110,6 +102,56 @@ export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
110
102
  */
111
103
  readonly customOptions?: TCustomOptions;
112
104
  };
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> = {
138
+ /**
139
+ * Was the login successful
140
+ */
141
+ readonly isSuccess: boolean;
142
+ /**
143
+ * Message to display to the user, this message is always displayed
144
+ */
145
+ readonly message?: string;
146
+ /**
147
+ * Optional error if the login was not successful
148
+ */
149
+ readonly error?: AuthenticationError;
150
+ /**
151
+ * Identification of the user to be used in the future requests
152
+ */
153
+ readonly identification?: Identification<TCustomOptions>;
154
+ };
113
155
  /**
114
156
  * TODO: Constrain anonymous mode for specific models / providers
115
157
  */
@@ -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-7",
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-7';
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,