@promptbook/pdf 0.88.0 → 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 +7 -1
- package/esm/index.es.js +160 -88
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +18 -6
- 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 -10
- 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 +9 -2
- package/esm/typings/src/llm-providers/_common/utils/count-total-usage/{countTotalUsage.d.ts → countUsage.d.ts} +1 -1
- 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/playground/playground.d.ts +5 -0
- 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} +5 -4
- 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 +88 -6
- 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 +8 -2
- package/esm/typings/src/utils/organization/TODO_narrow.d.ts +6 -0
- package/package.json +2 -2
- package/umd/index.umd.js +161 -89
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
<blockquote style="color: #ff8811">
|
|
27
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
28
|
+
</blockquote>
|
|
29
|
+
|
|
26
30
|
## 📦 Package `@promptbook/pdf`
|
|
27
31
|
|
|
28
32
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
|
@@ -198,7 +202,7 @@ Each part of the book defines one of 3 circles:
|
|
|
198
202
|
|
|
199
203
|
### **What:** Workflows, Tasks and Parameters
|
|
200
204
|
|
|
201
|
-
What work needs to be done. Each book defines a workflow, which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
|
|
205
|
+
What work needs to be done. Each book defines a [workflow *(scenario or pipeline)*](https://github.com/webgptorg/promptbook/discussions/88), which is one or more tasks. Each workflow has a fixed input and output. For example, you have a book that generates an article from a topic. Once it generates an article about AI, once about marketing, once about cooking. The workflow (= your AI program) is the same, only the input and output change.
|
|
202
206
|
|
|
203
207
|
**Related commands:**
|
|
204
208
|
|
|
@@ -308,6 +312,8 @@ The following glossary is used to clarify certain concepts:
|
|
|
308
312
|
|
|
309
313
|
|
|
310
314
|
|
|
315
|
+
|
|
316
|
+
|
|
311
317
|
_Note: This section is not complete dictionary, more list of general AI / LLM terms that has connection with Promptbook_
|
|
312
318
|
|
|
313
319
|
|
package/esm/index.es.js
CHANGED
|
@@ -26,7 +26,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
26
26
|
* @generated
|
|
27
27
|
* @see https://github.com/webgptorg/promptbook
|
|
28
28
|
*/
|
|
29
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
29
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.89.0-11';
|
|
30
30
|
/**
|
|
31
31
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
32
32
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -160,6 +160,7 @@ const DEFAULT_MAX_PARALLEL_COUNT = 5; // <- TODO: [🤹♂️]
|
|
|
160
160
|
*/
|
|
161
161
|
const DEFAULT_MAX_EXECUTION_ATTEMPTS = 10; // <- TODO: [🤹♂️]
|
|
162
162
|
// <- TODO: [🕝] Make also `BOOKS_DIRNAME_ALTERNATIVES`
|
|
163
|
+
// TODO: !!!!!! Just .promptbook dir, hardocode others
|
|
163
164
|
/**
|
|
164
165
|
* Where to store the temporary downloads
|
|
165
166
|
*
|
|
@@ -211,7 +212,7 @@ const IS_PIPELINE_LOGIC_VALIDATED = just(
|
|
|
211
212
|
true);
|
|
212
213
|
/**
|
|
213
214
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
214
|
-
* TODO: [🧠][🧜♂️] Maybe join
|
|
215
|
+
* TODO: [🧠][🧜♂️] Maybe join remoteServerUrl and path into single value
|
|
215
216
|
*/
|
|
216
217
|
|
|
217
218
|
/**
|
|
@@ -2147,6 +2148,19 @@ class CsvFormatError extends AbstractFormatError {
|
|
|
2147
2148
|
}
|
|
2148
2149
|
}
|
|
2149
2150
|
|
|
2151
|
+
/**
|
|
2152
|
+
* AuthenticationError is thrown from login function which is dependency of remote server
|
|
2153
|
+
*
|
|
2154
|
+
* @public exported from `@promptbook/core`
|
|
2155
|
+
*/
|
|
2156
|
+
class AuthenticationError extends Error {
|
|
2157
|
+
constructor(message) {
|
|
2158
|
+
super(message);
|
|
2159
|
+
this.name = 'AuthenticationError';
|
|
2160
|
+
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2150
2164
|
/**
|
|
2151
2165
|
* This error indicates that the pipeline collection cannot be propperly loaded
|
|
2152
2166
|
*
|
|
@@ -2212,6 +2226,19 @@ class NotYetImplementedError extends Error {
|
|
|
2212
2226
|
}
|
|
2213
2227
|
}
|
|
2214
2228
|
|
|
2229
|
+
/**
|
|
2230
|
+
* Error thrown when a fetch request fails
|
|
2231
|
+
*
|
|
2232
|
+
* @public exported from `@promptbook/core`
|
|
2233
|
+
*/
|
|
2234
|
+
class PromptbookFetchError extends Error {
|
|
2235
|
+
constructor(message) {
|
|
2236
|
+
super(message);
|
|
2237
|
+
this.name = 'PromptbookFetchError';
|
|
2238
|
+
Object.setPrototypeOf(this, PromptbookFetchError.prototype);
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2215
2242
|
/**
|
|
2216
2243
|
* Index of all custom errors
|
|
2217
2244
|
*
|
|
@@ -2249,6 +2276,8 @@ const COMMON_JAVASCRIPT_ERRORS = {
|
|
|
2249
2276
|
TypeError,
|
|
2250
2277
|
URIError,
|
|
2251
2278
|
AggregateError,
|
|
2279
|
+
AuthenticationError,
|
|
2280
|
+
PromptbookFetchError,
|
|
2252
2281
|
/*
|
|
2253
2282
|
Note: Not widely supported
|
|
2254
2283
|
> InternalError,
|
|
@@ -2310,6 +2339,7 @@ function assertsTaskSuccessful(executionResult) {
|
|
|
2310
2339
|
const { isSuccessful, errors, warnings } = executionResult;
|
|
2311
2340
|
for (const warning of warnings) {
|
|
2312
2341
|
console.warn(warning.message);
|
|
2342
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2313
2343
|
}
|
|
2314
2344
|
if (isSuccessful === true) {
|
|
2315
2345
|
return;
|
|
@@ -2447,6 +2477,10 @@ function serializeError(error) {
|
|
|
2447
2477
|
|
|
2448
2478
|
Cannot serialize error with name "${name}"
|
|
2449
2479
|
|
|
2480
|
+
Authors of Promptbook probably forgot to add this error into the list of errors:
|
|
2481
|
+
https://github.com/webgptorg/promptbook/blob/main/src/errors/0-index.ts
|
|
2482
|
+
|
|
2483
|
+
|
|
2450
2484
|
${block(stack || message)}
|
|
2451
2485
|
|
|
2452
2486
|
`));
|
|
@@ -2488,30 +2522,42 @@ async function forEachAsync(array, options, callbackfunction) {
|
|
|
2488
2522
|
await Promise.all(tasks);
|
|
2489
2523
|
}
|
|
2490
2524
|
|
|
2525
|
+
/**
|
|
2526
|
+
* Represents the uncertain value
|
|
2527
|
+
*
|
|
2528
|
+
* @public exported from `@promptbook/core`
|
|
2529
|
+
*/
|
|
2530
|
+
const ZERO_VALUE = $deepFreeze({ value: 0 });
|
|
2531
|
+
/**
|
|
2532
|
+
* Represents the uncertain value
|
|
2533
|
+
*
|
|
2534
|
+
* @public exported from `@promptbook/core`
|
|
2535
|
+
*/
|
|
2536
|
+
const UNCERTAIN_ZERO_VALUE = $deepFreeze({ value: 0, isUncertain: true });
|
|
2491
2537
|
/**
|
|
2492
2538
|
* Represents the usage with no resources consumed
|
|
2493
2539
|
*
|
|
2494
2540
|
* @public exported from `@promptbook/core`
|
|
2495
2541
|
*/
|
|
2496
2542
|
const ZERO_USAGE = $deepFreeze({
|
|
2497
|
-
price:
|
|
2543
|
+
price: ZERO_VALUE,
|
|
2498
2544
|
input: {
|
|
2499
|
-
tokensCount:
|
|
2500
|
-
charactersCount:
|
|
2501
|
-
wordsCount:
|
|
2502
|
-
sentencesCount:
|
|
2503
|
-
linesCount:
|
|
2504
|
-
paragraphsCount:
|
|
2505
|
-
pagesCount:
|
|
2545
|
+
tokensCount: ZERO_VALUE,
|
|
2546
|
+
charactersCount: ZERO_VALUE,
|
|
2547
|
+
wordsCount: ZERO_VALUE,
|
|
2548
|
+
sentencesCount: ZERO_VALUE,
|
|
2549
|
+
linesCount: ZERO_VALUE,
|
|
2550
|
+
paragraphsCount: ZERO_VALUE,
|
|
2551
|
+
pagesCount: ZERO_VALUE,
|
|
2506
2552
|
},
|
|
2507
2553
|
output: {
|
|
2508
|
-
tokensCount:
|
|
2509
|
-
charactersCount:
|
|
2510
|
-
wordsCount:
|
|
2511
|
-
sentencesCount:
|
|
2512
|
-
linesCount:
|
|
2513
|
-
paragraphsCount:
|
|
2514
|
-
pagesCount:
|
|
2554
|
+
tokensCount: ZERO_VALUE,
|
|
2555
|
+
charactersCount: ZERO_VALUE,
|
|
2556
|
+
wordsCount: ZERO_VALUE,
|
|
2557
|
+
sentencesCount: ZERO_VALUE,
|
|
2558
|
+
linesCount: ZERO_VALUE,
|
|
2559
|
+
paragraphsCount: ZERO_VALUE,
|
|
2560
|
+
pagesCount: ZERO_VALUE,
|
|
2515
2561
|
},
|
|
2516
2562
|
});
|
|
2517
2563
|
/**
|
|
@@ -2520,24 +2566,24 @@ const ZERO_USAGE = $deepFreeze({
|
|
|
2520
2566
|
* @public exported from `@promptbook/core`
|
|
2521
2567
|
*/
|
|
2522
2568
|
$deepFreeze({
|
|
2523
|
-
price:
|
|
2569
|
+
price: UNCERTAIN_ZERO_VALUE,
|
|
2524
2570
|
input: {
|
|
2525
|
-
tokensCount:
|
|
2526
|
-
charactersCount:
|
|
2527
|
-
wordsCount:
|
|
2528
|
-
sentencesCount:
|
|
2529
|
-
linesCount:
|
|
2530
|
-
paragraphsCount:
|
|
2531
|
-
pagesCount:
|
|
2571
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2572
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2573
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2574
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2575
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2576
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2577
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2532
2578
|
},
|
|
2533
2579
|
output: {
|
|
2534
|
-
tokensCount:
|
|
2535
|
-
charactersCount:
|
|
2536
|
-
wordsCount:
|
|
2537
|
-
sentencesCount:
|
|
2538
|
-
linesCount:
|
|
2539
|
-
paragraphsCount:
|
|
2540
|
-
pagesCount:
|
|
2580
|
+
tokensCount: UNCERTAIN_ZERO_VALUE,
|
|
2581
|
+
charactersCount: UNCERTAIN_ZERO_VALUE,
|
|
2582
|
+
wordsCount: UNCERTAIN_ZERO_VALUE,
|
|
2583
|
+
sentencesCount: UNCERTAIN_ZERO_VALUE,
|
|
2584
|
+
linesCount: UNCERTAIN_ZERO_VALUE,
|
|
2585
|
+
paragraphsCount: UNCERTAIN_ZERO_VALUE,
|
|
2586
|
+
pagesCount: UNCERTAIN_ZERO_VALUE,
|
|
2541
2587
|
},
|
|
2542
2588
|
});
|
|
2543
2589
|
/**
|
|
@@ -2598,8 +2644,9 @@ function addUsage(...usageItems) {
|
|
|
2598
2644
|
* @returns LLM tools with same functionality with added total cost counting
|
|
2599
2645
|
* @public exported from `@promptbook/core`
|
|
2600
2646
|
*/
|
|
2601
|
-
function
|
|
2647
|
+
function countUsage(llmTools) {
|
|
2602
2648
|
let totalUsage = ZERO_USAGE;
|
|
2649
|
+
const spending = new Subject();
|
|
2603
2650
|
const proxyTools = {
|
|
2604
2651
|
get title() {
|
|
2605
2652
|
// TODO: [🧠] Maybe put here some suffix
|
|
@@ -2609,12 +2656,15 @@ function countTotalUsage(llmTools) {
|
|
|
2609
2656
|
// TODO: [🧠] Maybe put here some suffix
|
|
2610
2657
|
return llmTools.description;
|
|
2611
2658
|
},
|
|
2612
|
-
|
|
2659
|
+
checkConfiguration() {
|
|
2613
2660
|
return /* not await */ llmTools.checkConfiguration();
|
|
2614
2661
|
},
|
|
2615
2662
|
listModels() {
|
|
2616
2663
|
return /* not await */ llmTools.listModels();
|
|
2617
2664
|
},
|
|
2665
|
+
spending() {
|
|
2666
|
+
return spending.asObservable();
|
|
2667
|
+
},
|
|
2618
2668
|
getTotalUsage() {
|
|
2619
2669
|
// <- Note: [🥫] Not using getter `get totalUsage` but `getTotalUsage` to allow this object to be proxied
|
|
2620
2670
|
return totalUsage;
|
|
@@ -2625,6 +2675,7 @@ function countTotalUsage(llmTools) {
|
|
|
2625
2675
|
// console.info('[🚕] callChatModel through countTotalUsage');
|
|
2626
2676
|
const promptResult = await llmTools.callChatModel(prompt);
|
|
2627
2677
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2678
|
+
spending.next(promptResult.usage);
|
|
2628
2679
|
return promptResult;
|
|
2629
2680
|
};
|
|
2630
2681
|
}
|
|
@@ -2633,6 +2684,7 @@ function countTotalUsage(llmTools) {
|
|
|
2633
2684
|
// console.info('[🚕] callCompletionModel through countTotalUsage');
|
|
2634
2685
|
const promptResult = await llmTools.callCompletionModel(prompt);
|
|
2635
2686
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2687
|
+
spending.next(promptResult.usage);
|
|
2636
2688
|
return promptResult;
|
|
2637
2689
|
};
|
|
2638
2690
|
}
|
|
@@ -2641,6 +2693,7 @@ function countTotalUsage(llmTools) {
|
|
|
2641
2693
|
// console.info('[🚕] callEmbeddingModel through countTotalUsage');
|
|
2642
2694
|
const promptResult = await llmTools.callEmbeddingModel(prompt);
|
|
2643
2695
|
totalUsage = addUsage(totalUsage, promptResult.usage);
|
|
2696
|
+
spending.next(promptResult.usage);
|
|
2644
2697
|
return promptResult;
|
|
2645
2698
|
};
|
|
2646
2699
|
}
|
|
@@ -2818,6 +2871,7 @@ function joinLlmExecutionTools(...llmExecutionTools) {
|
|
|
2818
2871
|
`);
|
|
2819
2872
|
// TODO: [🟥] Detect browser / node and make it colorfull
|
|
2820
2873
|
console.warn(warningMessage);
|
|
2874
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
2821
2875
|
/*
|
|
2822
2876
|
return {
|
|
2823
2877
|
async listModels() {
|
|
@@ -3203,17 +3257,24 @@ function mimeTypeToExtension(value) {
|
|
|
3203
3257
|
/**
|
|
3204
3258
|
* The built-in `fetch' function with a lightweight error handling wrapper as default fetch function used in Promptbook scrapers
|
|
3205
3259
|
*
|
|
3206
|
-
* @
|
|
3260
|
+
* @public exported from `@promptbook/core`
|
|
3207
3261
|
*/
|
|
3208
|
-
const
|
|
3262
|
+
const promptbookFetch = async (urlOrRequest, init) => {
|
|
3209
3263
|
try {
|
|
3210
|
-
return await fetch(
|
|
3264
|
+
return await fetch(urlOrRequest, init);
|
|
3211
3265
|
}
|
|
3212
3266
|
catch (error) {
|
|
3213
3267
|
if (!(error instanceof Error)) {
|
|
3214
3268
|
throw error;
|
|
3215
3269
|
}
|
|
3216
|
-
|
|
3270
|
+
let url;
|
|
3271
|
+
if (typeof urlOrRequest === 'string') {
|
|
3272
|
+
url = urlOrRequest;
|
|
3273
|
+
}
|
|
3274
|
+
else if (urlOrRequest instanceof Request) {
|
|
3275
|
+
url = urlOrRequest.url;
|
|
3276
|
+
}
|
|
3277
|
+
throw new PromptbookFetchError(spaceTrim((block) => `
|
|
3217
3278
|
Can not fetch "${url}"
|
|
3218
3279
|
|
|
3219
3280
|
Fetch error:
|
|
@@ -3234,7 +3295,7 @@ const scraperFetch = async (url, init) => {
|
|
|
3234
3295
|
async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
3235
3296
|
// console.log('!! makeKnowledgeSourceHandler', knowledgeSource);
|
|
3236
3297
|
var _a;
|
|
3237
|
-
const { fetch =
|
|
3298
|
+
const { fetch = promptbookFetch } = tools;
|
|
3238
3299
|
const { knowledgeSourceContent } = knowledgeSource;
|
|
3239
3300
|
let { name } = knowledgeSource;
|
|
3240
3301
|
const { rootDirname = null,
|
|
@@ -3375,63 +3436,73 @@ async function prepareKnowledgePieces(knowledgeSources, tools, options) {
|
|
|
3375
3436
|
const { maxParallelCount = DEFAULT_MAX_PARALLEL_COUNT, rootDirname, isVerbose = DEFAULT_IS_VERBOSE } = options;
|
|
3376
3437
|
const knowledgePreparedUnflatten = new Array(knowledgeSources.length);
|
|
3377
3438
|
await forEachAsync(knowledgeSources, { maxParallelCount }, async (knowledgeSource, index) => {
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3439
|
+
try {
|
|
3440
|
+
let partialPieces = null;
|
|
3441
|
+
const sourceHandler = await makeKnowledgeSourceHandler(knowledgeSource, tools, { rootDirname, isVerbose });
|
|
3442
|
+
const scrapers = arrayableToArray(tools.scrapers);
|
|
3443
|
+
for (const scraper of scrapers) {
|
|
3444
|
+
if (!scraper.metadata.mimeTypes.includes(sourceHandler.mimeType)
|
|
3445
|
+
// <- TODO: [🦔] Implement mime-type wildcards
|
|
3446
|
+
) {
|
|
3447
|
+
continue;
|
|
3448
|
+
}
|
|
3449
|
+
const partialPiecesUnchecked = await scraper.scrape(sourceHandler);
|
|
3450
|
+
if (partialPiecesUnchecked !== null) {
|
|
3451
|
+
partialPieces = [...partialPiecesUnchecked];
|
|
3452
|
+
// <- TODO: [🪓] Here should be no need for spreading new array, just `partialPieces = partialPiecesUnchecked`
|
|
3453
|
+
break;
|
|
3454
|
+
}
|
|
3455
|
+
console.warn(spaceTrim((block) => `
|
|
3456
|
+
Cannot scrape knowledge from source despite the scraper \`${scraper.metadata.className}\` supports the mime type "${sourceHandler.mimeType}".
|
|
3395
3457
|
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3458
|
+
The source:
|
|
3459
|
+
${block(knowledgeSource.knowledgeSourceContent
|
|
3460
|
+
.split('\n')
|
|
3461
|
+
.map((line) => `> ${line}`)
|
|
3462
|
+
.join('\n'))}
|
|
3401
3463
|
|
|
3402
|
-
|
|
3464
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3403
3465
|
|
|
3404
3466
|
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3467
|
+
`));
|
|
3468
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3469
|
+
}
|
|
3470
|
+
if (partialPieces === null) {
|
|
3471
|
+
throw new KnowledgeScrapeError(spaceTrim((block) => `
|
|
3472
|
+
Cannot scrape knowledge
|
|
3410
3473
|
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3474
|
+
The source:
|
|
3475
|
+
> ${block(knowledgeSource.knowledgeSourceContent
|
|
3476
|
+
.split('\n')
|
|
3477
|
+
.map((line) => `> ${line}`)
|
|
3478
|
+
.join('\n'))}
|
|
3416
3479
|
|
|
3417
|
-
|
|
3480
|
+
No scraper found for the mime type "${sourceHandler.mimeType}"
|
|
3418
3481
|
|
|
3419
|
-
|
|
3482
|
+
${block($registeredScrapersMessage(scrapers))}
|
|
3420
3483
|
|
|
3421
3484
|
|
|
3422
|
-
|
|
3485
|
+
`));
|
|
3486
|
+
}
|
|
3487
|
+
const pieces = partialPieces.map((partialPiece) => ({
|
|
3488
|
+
...partialPiece,
|
|
3489
|
+
sources: [
|
|
3490
|
+
{
|
|
3491
|
+
name: knowledgeSource.name,
|
|
3492
|
+
// line, column <- TODO: [☀]
|
|
3493
|
+
// <- TODO: [❎]
|
|
3494
|
+
},
|
|
3495
|
+
],
|
|
3496
|
+
}));
|
|
3497
|
+
knowledgePreparedUnflatten[index] = pieces;
|
|
3498
|
+
}
|
|
3499
|
+
catch (error) {
|
|
3500
|
+
if (!(error instanceof Error)) {
|
|
3501
|
+
throw error;
|
|
3502
|
+
}
|
|
3503
|
+
console.warn(error);
|
|
3504
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
3423
3505
|
}
|
|
3424
|
-
const pieces = partialPieces.map((partialPiece) => ({
|
|
3425
|
-
...partialPiece,
|
|
3426
|
-
sources: [
|
|
3427
|
-
{
|
|
3428
|
-
name: knowledgeSource.name,
|
|
3429
|
-
// line, column <- TODO: [☀]
|
|
3430
|
-
// <- TODO: [❎]
|
|
3431
|
-
},
|
|
3432
|
-
],
|
|
3433
|
-
}));
|
|
3434
|
-
knowledgePreparedUnflatten[index] = pieces;
|
|
3435
3506
|
});
|
|
3436
3507
|
const knowledgePrepared = knowledgePreparedUnflatten.flat();
|
|
3437
3508
|
return knowledgePrepared;
|
|
@@ -3537,7 +3608,7 @@ async function preparePipeline(pipeline, tools, options) {
|
|
|
3537
3608
|
// TODO: [🚐] Make arrayable LLMs -> single LLM DRY
|
|
3538
3609
|
const _llms = arrayableToArray(tools.llm);
|
|
3539
3610
|
const llmTools = _llms.length === 1 ? _llms[0] : joinLlmExecutionTools(..._llms);
|
|
3540
|
-
const llmToolsWithUsage =
|
|
3611
|
+
const llmToolsWithUsage = countUsage(llmTools);
|
|
3541
3612
|
// <- TODO: [🌯]
|
|
3542
3613
|
/*
|
|
3543
3614
|
TODO: [🧠][🪑][🔃] Should this be done or not
|
|
@@ -3849,7 +3920,7 @@ function extractParameterNamesFromTask(task) {
|
|
|
3849
3920
|
if (parameterNames.has(subparameterName)) {
|
|
3850
3921
|
parameterNames.delete(subparameterName);
|
|
3851
3922
|
parameterNames.add(foreach.parameterName);
|
|
3852
|
-
// <- TODO: [
|
|
3923
|
+
// <- TODO: [🏮] Warn/logic error when `subparameterName` not used
|
|
3853
3924
|
}
|
|
3854
3925
|
}
|
|
3855
3926
|
}
|
|
@@ -5445,6 +5516,7 @@ function createPipelineExecutor(options) {
|
|
|
5445
5516
|
|
|
5446
5517
|
@see more at https://ptbk.io/prepare-pipeline
|
|
5447
5518
|
`));
|
|
5519
|
+
// <- TODO: [🏮] Some standard way how to transform errors into warnings and how to handle non-critical fails during the tasks
|
|
5448
5520
|
}
|
|
5449
5521
|
let runCount = 0;
|
|
5450
5522
|
const pipelineExecutorWithCallback = async (inputParameters, onProgress) => {
|