@promptbook/pdf 0.89.0-1 → 0.89.0-11
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.
- package/README.md +3 -1
- package/esm/index.es.js +150 -85
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +16 -4
- package/esm/typings/src/_packages/remote-client.index.d.ts +6 -8
- package/esm/typings/src/_packages/remote-server.index.d.ts +6 -6
- package/esm/typings/src/_packages/types.index.d.ts +18 -20
- package/esm/typings/src/cli/cli-commands/login.d.ts +15 -0
- package/esm/typings/src/cli/common/$addGlobalOptionsToCommand.d.ts +7 -0
- package/esm/typings/src/cli/common/$provideLlmToolsForCli.d.ts +15 -0
- package/esm/typings/src/config.d.ts +15 -8
- package/esm/typings/src/errors/0-index.d.ts +6 -0
- package/esm/typings/src/errors/AuthenticationError.d.ts +9 -0
- package/esm/typings/src/errors/PromptbookFetchError.d.ts +9 -0
- package/esm/typings/src/execution/PipelineExecutorResult.d.ts +2 -2
- package/esm/typings/src/execution/PromptResult.d.ts +2 -2
- package/esm/typings/src/execution/{PromptResultUsage.d.ts → Usage.d.ts} +5 -5
- package/esm/typings/src/execution/utils/addUsage.d.ts +2 -2
- package/esm/typings/src/execution/utils/computeUsageCounts.d.ts +3 -3
- package/esm/typings/src/execution/utils/usage-constants.d.ts +77 -60
- package/esm/typings/src/execution/utils/usageToHuman.d.ts +5 -5
- package/esm/typings/src/execution/utils/usageToWorktime.d.ts +5 -5
- package/esm/typings/src/llm-providers/_common/register/$provideEnvFilename.d.ts +12 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsConfigurationFromEnv.d.ts +2 -8
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForTestingAndScriptsAndPlayground.d.ts +2 -0
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsForWizzardOrCli.d.ts +36 -1
- package/esm/typings/src/llm-providers/_common/register/$provideLlmToolsFromEnv.d.ts +1 -0
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/LlmExecutionToolsWithTotalUsage.d.ts +3 -3
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/limitTotalUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionToolsOptions.d.ts +1 -1
- package/esm/typings/src/llm-providers/anthropic-claude/computeAnthropicClaudeUsage.d.ts +2 -2
- package/esm/typings/src/llm-providers/anthropic-claude/register-configuration.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +0 -9
- package/esm/typings/src/llm-providers/openai/computeOpenAiUsage.d.ts +2 -2
- package/esm/typings/src/pipeline/PipelineJson/PreparationJson.d.ts +2 -2
- package/esm/typings/src/remote-server/RemoteServer.d.ts +23 -0
- package/esm/typings/src/remote-server/socket-types/_subtypes/{PromptbookServer_Identification.d.ts → Identification.d.ts} +3 -3
- package/esm/typings/src/remote-server/socket-types/listModels/PromptbookServer_ListModels_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prepare/PromptbookServer_PreparePipeline_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/socket-types/prompt/PromptbookServer_Prompt_Request.d.ts +2 -2
- package/esm/typings/src/remote-server/startRemoteServer.d.ts +2 -2
- package/esm/typings/src/remote-server/types/RemoteClientOptions.d.ts +4 -12
- package/esm/typings/src/remote-server/types/RemoteServerOptions.d.ts +73 -3
- package/esm/typings/src/scrapers/_common/utils/{scraperFetch.d.ts → promptbookFetch.d.ts} +2 -2
- package/esm/typings/src/storage/env-storage/$EnvStorage.d.ts +37 -0
- package/esm/typings/src/types/typeAliases.d.ts +6 -0
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +2 -2
- package/umd/index.umd.js +151 -86
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/playground/BrjappConnector.d.ts +0 -64
- package/esm/typings/src/playground/brjapp-api-schema.d.ts +0 -12879
|
@@ -1,10 +1,15 @@
|
|
|
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';
|
|
8
|
+
import type { string_email } from '../../types/typeAliases';
|
|
9
|
+
import type { string_password } from '../../types/typeAliases';
|
|
6
10
|
import type { string_uri } from '../../types/typeAliases';
|
|
7
11
|
import type { string_user_id } from '../../types/typeAliases';
|
|
12
|
+
import type { Identification } from '../socket-types/_subtypes/Identification';
|
|
8
13
|
/**
|
|
9
14
|
* @@@
|
|
10
15
|
*
|
|
@@ -16,7 +21,6 @@ import type { string_user_id } from '../../types/typeAliases';
|
|
|
16
21
|
*
|
|
17
22
|
* You can enable both modes at the same time.
|
|
18
23
|
*
|
|
19
|
-
* @public exported from `@promptbook/remote-client`
|
|
20
24
|
* @public exported from `@promptbook/remote-server`
|
|
21
25
|
*/
|
|
22
26
|
export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
|
|
@@ -32,8 +36,12 @@ export type RemoteServerOptions<TCustomOptions> = CommonToolsOptions & {
|
|
|
32
36
|
* @default '/'
|
|
33
37
|
* @example '/api/promptbook/'
|
|
34
38
|
*/
|
|
35
|
-
readonly rootPath
|
|
36
|
-
} & (
|
|
39
|
+
readonly rootPath?: string_uri;
|
|
40
|
+
} & ((AnonymousRemoteServerOptions & {
|
|
41
|
+
readonly isApplicationModeAllowed?: false;
|
|
42
|
+
}) | ({
|
|
43
|
+
readonly isAnonymousModeAllowed?: false;
|
|
44
|
+
} & ApplicationRemoteServerOptions<TCustomOptions>) | (AnonymousRemoteServerOptions & ApplicationRemoteServerOptions<TCustomOptions>));
|
|
37
45
|
export type AnonymousRemoteServerOptions = {
|
|
38
46
|
/**
|
|
39
47
|
* Enable anonymous mode
|
|
@@ -51,6 +59,18 @@ export type ApplicationRemoteServerOptions<TCustomOptions> = {
|
|
|
51
59
|
* This is used to check validity of the prompt to prevent misuse
|
|
52
60
|
*/
|
|
53
61
|
readonly collection: PipelineCollection;
|
|
62
|
+
/**
|
|
63
|
+
* User tries to login to the server, this function will be called verify the user and return the identification or throw an error
|
|
64
|
+
* This can be also doubled as a function to register the user
|
|
65
|
+
*
|
|
66
|
+
* Note: In most cases, you will return `PromptbookServer_ApplicationIdentification`
|
|
67
|
+
* `PromptbookServer_AnonymousIdentification` is useful only in scenarios when user stores its own api keys on the application server and
|
|
68
|
+
* server acts only as a api key provider
|
|
69
|
+
*
|
|
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>>;
|
|
54
74
|
/**
|
|
55
75
|
* Creates llm execution tools for each client
|
|
56
76
|
*/
|
|
@@ -82,6 +102,56 @@ export type ApplicationRemoteServerClientOptions<TCustomOptions> = {
|
|
|
82
102
|
*/
|
|
83
103
|
readonly customOptions?: TCustomOptions;
|
|
84
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
|
+
};
|
|
85
155
|
/**
|
|
86
156
|
* TODO: Constrain anonymous mode for specific models / providers
|
|
87
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
|
-
* @
|
|
5
|
+
* @public exported from `@promptbook/core`
|
|
6
6
|
*/
|
|
7
|
-
export declare const
|
|
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
|
*/
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PromptbookStorage } from '../_common/PromptbookStorage';
|
|
2
|
+
/**
|
|
3
|
+
* Stores data in .env variables (Remove !!! nonce 1)
|
|
4
|
+
*
|
|
5
|
+
* Note: `$` is used to indicate that this function is not a pure function - it uses filesystem to access `.env` file and also writes to `process.env`
|
|
6
|
+
*
|
|
7
|
+
* @private within the repository - for CLI utils
|
|
8
|
+
*/
|
|
9
|
+
export declare class $EnvStorage<TItem> implements PromptbookStorage<TItem> {
|
|
10
|
+
private envFilename;
|
|
11
|
+
private $provideOrCreateEnvFile;
|
|
12
|
+
private transformKey;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the number of key/value pairs currently present in the list associated with the object.
|
|
15
|
+
*/
|
|
16
|
+
get length(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Empties the list associated with the object of all key/value pairs, if there are any.
|
|
19
|
+
*/
|
|
20
|
+
clear(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the current value associated with the given key, or null if the given key does not exist in the list associated with the object.
|
|
23
|
+
*/
|
|
24
|
+
getItem(key: string): Promise<TItem | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the name of the nth key in the list, or null if n is greater than or equal to the number of key/value pairs in the object.
|
|
27
|
+
*/
|
|
28
|
+
key(index: number): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
|
31
|
+
*/
|
|
32
|
+
setItem(key: string, value: TItem): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Removes the key/value pair with the given key from the list associated with the object, if a key/value pair with the given key exists.
|
|
35
|
+
*/
|
|
36
|
+
removeItem(key: string): void;
|
|
37
|
+
}
|
|
@@ -242,6 +242,12 @@ export type string_promptbook_documentation_url = `https://github.com/webgptorg/
|
|
|
242
242
|
* For example `"towns.cz"`
|
|
243
243
|
*/
|
|
244
244
|
export type string_domain = string;
|
|
245
|
+
/**
|
|
246
|
+
* Semantic helper
|
|
247
|
+
*
|
|
248
|
+
* For example `"https://*.pavolhejny.com/*"`
|
|
249
|
+
*/
|
|
250
|
+
export type string_origin = string;
|
|
245
251
|
/**
|
|
246
252
|
* Semantic helper
|
|
247
253
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/pdf",
|
|
3
|
-
"version": "0.89.0-
|
|
3
|
+
"version": "0.89.0-11",
|
|
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/pdf.index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@promptbook/core": "0.89.0-
|
|
50
|
+
"@promptbook/core": "0.89.0-11"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"crypto": "^1.0.1",
|
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-
|
|
28
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
|
|
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
|
|
@@ -159,6 +159,7 @@
|
|
|
159
159
|
*/
|
|
160
160
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
161
161
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
162
|
+
// TODO: !!!!!! Just .promptbook dir, hardocode others
|
|
162
163
|
/**
|
|
163
164
|
* Where to store the temporary downloads
|
|
164
165
|
*
|
|
@@ -210,7 +211,7 @@
|
|
|
210
211
|
true);
|
|
211
212
|
/**
|
|
212
213
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
213
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
214
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
214
215
|
*/
|
|
215
216
|
|
|
216
217
|
/**
|
|
@@ -2146,6 +2147,19 @@
|
|
|
2146
2147
|
}
|
|
2147
2148
|
}
|
|
2148
2149
|
|
|
2150
|
+
/**
|
|
2151
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
2152
|
+
*
|
|
2153
|
+
* @public exported from `@promptbook/core`
|
|
2154
|
+
*/
|
|
2155
|
+
class AuthenticationError extends Error {
|
|
2156
|
+
constructor(message) {
|
|
2157
|
+
super(message);
|
|
2158
|
+
this.name = 'AuthenticationError';
|
|
2159
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2149
2163
|
/**
|
|
2150
2164
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2151
2165
|
*
|
|
@@ -2211,6 +2225,19 @@
|
|
|
2211
2225
|
}
|
|
2212
2226
|
}
|
|
2213
2227
|
|
|
2228
|
+
/**
|
|
2229
|
+
* Error thrown when a fetch request fails
|
|
2230
|
+
*
|
|
2231
|
+
* @public exported from `@promptbook/core`
|
|
2232
|
+
*/
|
|
2233
|
+
class PromptbookFetchError extends Error {
|
|
2234
|
+
constructor(message) {
|
|
2235
|
+
super(message);
|
|
2236
|
+
this.name = 'PromptbookFetchError';
|
|
2237
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2214
2241
|
/**
|
|
2215
2242
|
* Index of all custom errors
|
|
2216
2243
|
*
|
|
@@ -2248,6 +2275,8 @@
|
|
|
2248
2275
|
TypeError,
|
|
2249
2276
|
URIError,
|
|
2250
2277
|
AggregateError,
|
|
2278
|
+
AuthenticationError,
|
|
2279
|
+
PromptbookFetchError,
|
|
2251
2280
|
/*
|
|
2252
2281
|
Note: Not widely supported
|
|
2253
2282
|
> InternalError,
|
|
@@ -2309,6 +2338,7 @@
|
|
|
2309
2338
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
2310
2339
|
for (const warning of warnings) {
|
|
2311
2340
|
console.warn(warning.message);
|
|
2341
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2312
2342
|
}
|
|
2313
2343
|
if (isSuccessful === true) {
|
|
2314
2344
|
return;
|
|
@@ -2446,6 +2476,10 @@
|
|
|
2446
2476
|
|
|
2447
2477
|
Cannot serialize error with name "${name}"
|
|
2448
2478
|
|
|
2479
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2480
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2481
|
+
|
|
2482
|
+
|
|
2449
2483
|
${block(stack || message)}
|
|
2450
2484
|
|
|
2451
2485
|
`));
|
|
@@ -2487,30 +2521,42 @@
|
|
|
2487
2521
|
await Promise.all(tasks);
|
|
2488
2522
|
}
|
|
2489
2523
|
|
|
2524
|
+
/**
|
|
2525
|
+
* Represents the uncertain value
|
|
2526
|
+
*
|
|
2527
|
+
* @public exported from `@promptbook/core`
|
|
2528
|
+
*/
|
|
2529
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2530
|
+
/**
|
|
2531
|
+
* Represents the uncertain value
|
|
2532
|
+
*
|
|
2533
|
+
* @public exported from `@promptbook/core`
|
|
2534
|
+
*/
|
|
2535
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2490
2536
|
/**
|
|
2491
2537
|
* Represents the usage with no resources consumed
|
|
2492
2538
|
*
|
|
2493
2539
|
* @public exported from `@promptbook/core`
|
|
2494
2540
|
*/
|
|
2495
2541
|
const ZERO_USAGE = $deepFreeze({
|
|
2496
|
-
price:
|
|
2542
|
+
price: ZERO_VALUE,
|
|
2497
2543
|
input: {
|
|
2498
|
-
tokensCount:
|
|
2499
|
-
charactersCount:
|
|
2500
|
-
wordsCount:
|
|
2501
|
-
sentencesCount:
|
|
2502
|
-
linesCount:
|
|
2503
|
-
paragraphsCount:
|
|
2504
|
-
pagesCount:
|
|
2544
|
+
tokensCount: ZERO_VALUE,
|
|
2545
|
+
charactersCount: ZERO_VALUE,
|
|
2546
|
+
wordsCount: ZERO_VALUE,
|
|
2547
|
+
sentencesCount: ZERO_VALUE,
|
|
2548
|
+
linesCount: ZERO_VALUE,
|
|
2549
|
+
paragraphsCount: ZERO_VALUE,
|
|
2550
|
+
pagesCount: ZERO_VALUE,
|
|
2505
2551
|
},
|
|
2506
2552
|
output: {
|
|
2507
|
-
tokensCount:
|
|
2508
|
-
charactersCount:
|
|
2509
|
-
wordsCount:
|
|
2510
|
-
sentencesCount:
|
|
2511
|
-
linesCount:
|
|
2512
|
-
paragraphsCount:
|
|
2513
|
-
pagesCount:
|
|
2553
|
+
tokensCount: ZERO_VALUE,
|
|
2554
|
+
charactersCount: ZERO_VALUE,
|
|
2555
|
+
wordsCount: ZERO_VALUE,
|
|
2556
|
+
sentencesCount: ZERO_VALUE,
|
|
2557
|
+
linesCount: ZERO_VALUE,
|
|
2558
|
+
paragraphsCount: ZERO_VALUE,
|
|
2559
|
+
pagesCount: ZERO_VALUE,
|
|
2514
2560
|
},
|
|
2515
2561
|
});
|
|
2516
2562
|
/**
|
|
@@ -2519,24 +2565,24 @@
|
|
|
2519
2565
|
* @public exported from `@promptbook/core`
|
|
2520
2566
|
*/
|
|
2521
2567
|
$deepFreeze({
|
|
2522
|
-
price:
|
|
2568
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2523
2569
|
input: {
|
|
2524
|
-
tokensCount:
|
|
2525
|
-
charactersCount:
|
|
2526
|
-
wordsCount:
|
|
2527
|
-
sentencesCount:
|
|
2528
|
-
linesCount:
|
|
2529
|
-
paragraphsCount:
|
|
2530
|
-
pagesCount:
|
|
2570
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2571
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2572
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2573
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2574
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2575
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2576
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2531
2577
|
},
|
|
2532
2578
|
output: {
|
|
2533
|
-
tokensCount:
|
|
2534
|
-
charactersCount:
|
|
2535
|
-
wordsCount:
|
|
2536
|
-
sentencesCount:
|
|
2537
|
-
linesCount:
|
|
2538
|
-
paragraphsCount:
|
|
2539
|
-
pagesCount:
|
|
2579
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2580
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2581
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2582
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2583
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2584
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2585
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2540
2586
|
},
|
|
2541
2587
|
});
|
|
2542
2588
|
/**
|
|
@@ -2824,6 +2870,7 @@
|
|
|
2824
2870
|
`);
|
|
2825
2871
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2826
2872
|
console.warn(warningMessage);
|
|
2873
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2827
2874
|
/*
|
|
2828
2875
|
return {
|
|
2829
2876
|
async listModels() {
|
|
@@ -3209,17 +3256,24 @@
|
|
|
3209
3256
|
/**
|
|
3210
3257
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3211
3258
|
*
|
|
3212
|
-
* @
|
|
3259
|
+
* @public exported from `@promptbook/core`
|
|
3213
3260
|
*/
|
|
3214
|
-
const
|
|
3261
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3215
3262
|
try {
|
|
3216
|
-
return await fetch(
|
|
3263
|
+
return await fetch(urlOrRequest, init);
|
|
3217
3264
|
}
|
|
3218
3265
|
catch (error) {
|
|
3219
3266
|
if (!(error instanceof Error)) {
|
|
3220
3267
|
throw error;
|
|
3221
3268
|
}
|
|
3222
|
-
|
|
3269
|
+
let url;
|
|
3270
|
+
if (typeof urlOrRequest === 'string') {
|
|
3271
|
+
url = urlOrRequest;
|
|
3272
|
+
}
|
|
3273
|
+
else if (urlOrRequest instanceof Request) {
|
|
3274
|
+
url = urlOrRequest.url;
|
|
3275
|
+
}
|
|
3276
|
+
throw new PromptbookFetchError(spaceTrim__default["default"]((block) => `
|
|
3223
3277
|
Can not fetch "${url}"
|
|
3224
3278
|
|
|
3225
3279
|
Fetch error:
|
|
@@ -3240,7 +3294,7 @@
|
|
|
3240
3294
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3241
3295
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3242
3296
|
var _a;
|
|
3243
|
-
const { fetch =
|
|
3297
|
+
const { fetch = promptbookFetch } = tools;
|
|
3244
3298
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3245
3299
|
let { name } = knowledgeSource;
|
|
3246
3300
|
const { rootDirname = null,
|
|
@@ -3381,63 +3435,73 @@
|
|
|
3381
3435
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3382
3436
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3383
3437
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3438
|
+
try {
|
|
3439
|
+
let partialPieces = null;
|
|
3440
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
3441
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
3442
|
+
for (const scraper of scrapers) {
|
|
3443
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
3444
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
3445
|
+
) {
|
|
3446
|
+
continue;
|
|
3447
|
+
}
|
|
3448
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
3449
|
+
if (partialPiecesUnchecked !== null) {
|
|
3450
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
3451
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3452
|
+
break;
|
|
3453
|
+
}
|
|
3454
|
+
console.warn(spaceTrim__default["default"]((block) => `
|
|
3455
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
3401
3456
|
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3457
|
+
The source:
|
|
3458
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3459
|
+
.split('\n')
|
|
3460
|
+
.map((line) => `> ${line}`)
|
|
3461
|
+
.join('\n'))}
|
|
3407
3462
|
|
|
3408
|
-
|
|
3463
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3409
3464
|
|
|
3410
3465
|
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
The source:
|
|
3418
|
-
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3419
|
-
.split('\n')
|
|
3420
|
-
.map((line) => `> ${line}`)
|
|
3421
|
-
.join('\n'))}
|
|
3466
|
+
`));
|
|
3467
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3468
|
+
}
|
|
3469
|
+
if (partialPieces === null) {
|
|
3470
|
+
throw new KnowledgeScrapeError(spaceTrim__default["default"]((block) => `
|
|
3471
|
+
Cannot scrape knowledge
|
|
3422
3472
|
|
|
3423
|
-
|
|
3473
|
+
The source:
|
|
3474
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3475
|
+
.split('\n')
|
|
3476
|
+
.map((line) => `> ${line}`)
|
|
3477
|
+
.join('\n'))}
|
|
3424
3478
|
|
|
3425
|
-
|
|
3479
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3426
3480
|
|
|
3481
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3427
3482
|
|
|
3428
|
-
|
|
3483
|
+
|
|
3484
|
+
`));
|
|
3485
|
+
}
|
|
3486
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
3487
|
+
...partialPiece,
|
|
3488
|
+
sources: [
|
|
3489
|
+
{
|
|
3490
|
+
name: knowledgeSource.name,
|
|
3491
|
+
// line, column <- TODO: [☀]
|
|
3492
|
+
// <- TODO: [❎]
|
|
3493
|
+
},
|
|
3494
|
+
],
|
|
3495
|
+
}));
|
|
3496
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
3497
|
+
}
|
|
3498
|
+
catch (error) {
|
|
3499
|
+
if (!(error instanceof Error)) {
|
|
3500
|
+
throw error;
|
|
3501
|
+
}
|
|
3502
|
+
console.warn(error);
|
|
3503
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3429
3504
|
}
|
|
3430
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
3431
|
-
...partialPiece,
|
|
3432
|
-
sources: [
|
|
3433
|
-
{
|
|
3434
|
-
name: knowledgeSource.name,
|
|
3435
|
-
// line, column <- TODO: [☀]
|
|
3436
|
-
// <- TODO: [❎]
|
|
3437
|
-
},
|
|
3438
|
-
],
|
|
3439
|
-
}));
|
|
3440
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
3441
3505
|
});
|
|
3442
3506
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3443
3507
|
return knowledgePrepared;
|
|
@@ -3855,7 +3919,7 @@
|
|
|
3855
3919
|
if (parameterNames.has(subparameterName)) {
|
|
3856
3920
|
parameterNames.delete(subparameterName);
|
|
3857
3921
|
parameterNames.add(foreach.parameterName);
|
|
3858
|
-
// <- TODO: [
|
|
3922
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
3859
3923
|
}
|
|
3860
3924
|
}
|
|
3861
3925
|
}
|
|
@@ -5451,6 +5515,7 @@
|
|
|
5451
5515
|
|
|
5452
5516
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5453
5517
|
`));
|
|
5518
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5454
5519
|
}
|
|
5455
5520
|
let runCount = 0;
|
|
5456
5521
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|